Class: Guard::Haskell::Repl

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

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.



26
27
28
29
30
# File 'lib/guard/haskell/repl.rb', line 26

def initialize(cabal_target, repl_options)
  @listening = false
  @status = :success
  start("cabal", "repl", cabal_target, *repl_options)
end

Instance Attribute Details

#inferiorObject (readonly)

Returns the value of attribute inferior.



4
5
6
# File 'lib/guard/haskell/repl.rb', line 4

def inferior
  @inferior
end

#listenerObject (readonly)

Returns the value of attribute listener.



4
5
6
# File 'lib/guard/haskell/repl.rb', line 4

def listener
  @listener
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/guard/haskell/repl.rb', line 4

def status
  @status
end

#stdinObject (readonly)

Returns the value of attribute stdin.



4
5
6
# File 'lib/guard/haskell/repl.rb', line 4

def stdin
  @stdin
end

Class Method Details

.finished_with(str) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/guard/haskell/repl.rb', line 6

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



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

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

#reload_and_rerunObject



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

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



44
45
46
47
48
49
50
51
52
# File 'lib/guard/haskell/repl.rb', line 44

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



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

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