Class: Guard::Haskell::Repl

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/haskell/repl.rb

Defined Under Namespace

Classes: NoCabalFile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cabal_target, repl_options) ⇒ Repl

Returns a new instance of Repl

Raises:


32
33
34
35
36
37
# File 'lib/guard/haskell/repl.rb', line 32

def initialize(cabal_target, repl_options)
  @listening = false
  @status = :success
  raise NoCabalFile if Dir.glob('*.cabal').empty?
  start("cabal", "repl", cabal_target, *repl_options)
end

Instance Attribute Details

#inferiorObject (readonly)

Returns the value of attribute inferior


10
11
12
# File 'lib/guard/haskell/repl.rb', line 10

def inferior
  @inferior
end

#listenerObject (readonly)

Returns the value of attribute listener


10
11
12
# File 'lib/guard/haskell/repl.rb', line 10

def listener
  @listener
end

#statusObject (readonly)

Returns the value of attribute status


10
11
12
# File 'lib/guard/haskell/repl.rb', line 10

def status
  @status
end

#stdinObject (readonly)

Returns the value of attribute stdin


10
11
12
# File 'lib/guard/haskell/repl.rb', line 10

def stdin
  @stdin
end

Class Method Details

.finished_with(str) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/guard/haskell/repl.rb', line 12

def self.finished_with(str)
  case str
  when /\d+ examples?, 0 failures/,
       /Ok, modules loaded:/
    :success
  when /\d+ examples?, \d+ failures?/
    :runtime_failure
  when /Failed, modules loaded:/,
       /\*{3} Exception:/,
       /cannot find object file for module/,
       /phase `C pre-processor' failed/,
       /phase `Haskell pre-processor' failed/,
       /phase `Linker' failed/,
       /GHCi runtime linker: fatal error:/,
       /During interactive linking, GHCi couldn't find the following symbol:/,
       /ghc: could not execute:/
    :compile_failure
  end
end

Instance Method Details

#exitObject


46
47
48
49
# File 'lib/guard/haskell/repl.rb', line 46

def exit
  stdin.write(":quit\n")
  ::Thread.kill(listener)
end

#reload_and_rerunObject


61
62
63
64
65
# File 'lib/guard/haskell/repl.rb', line 61

def reload_and_rerun
  if run_command_and_wait_for_result(":reload\n")
    run_command_and_wait_for_result(":main --color --rerun\n")
  end
end

#reload_and_run_matching(pattern = nil) ⇒ Object


51
52
53
54
55
56
57
58
59
# File 'lib/guard/haskell/repl.rb', line 51

def reload_and_run_matching(pattern = nil)
  if run_command_and_wait_for_result(":reload\n")
    if pattern.nil?
      run_command_and_wait_for_result(":main --color\n")
    else
      run_command_and_wait_for_result(":main --color --match #{pattern}\n")
    end
  end
end

#start(*cmd) ⇒ Object


39
40
41
42
43
44
# File 'lib/guard/haskell/repl.rb', line 39

def start(*cmd)
  @listening = true
  @stdin, stdout, @inferior = ::Open3.popen2e(*cmd)
  @listener = ::Thread.new { listen_or_die(stdout, STDOUT) }
  wait_for_result
end