Class: Guard::Haskell::Repl
- Inherits:
-
Object
- Object
- Guard::Haskell::Repl
- Defined in:
- lib/guard/haskell/repl.rb
Defined Under Namespace
Classes: NoCabalFile
Instance Attribute Summary collapse
-
#inferior ⇒ Object
readonly
Returns the value of attribute inferior.
-
#listener ⇒ Object
readonly
Returns the value of attribute listener.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
Class Method Summary collapse
Instance Method Summary collapse
- #exit ⇒ Object
-
#initialize(cabal_target, repl_options) ⇒ Repl
constructor
A new instance of Repl.
- #reload_and_rerun ⇒ Object
- #reload_and_run_matching(pattern = nil) ⇒ Object
- #start(*cmd) ⇒ Object
Constructor Details
#initialize(cabal_target, repl_options) ⇒ Repl
Returns a new instance of Repl.
32 33 34 35 36 37 |
# File 'lib/guard/haskell/repl.rb', line 32 def initialize(cabal_target, ) @listening = false @status = :success raise NoCabalFile if Dir.glob('*.cabal').empty? start("cabal", "repl", cabal_target, *) end |
Instance Attribute Details
#inferior ⇒ Object (readonly)
Returns the value of attribute inferior.
10 11 12 |
# File 'lib/guard/haskell/repl.rb', line 10 def inferior @inferior end |
#listener ⇒ Object (readonly)
Returns the value of attribute listener.
10 11 12 |
# File 'lib/guard/haskell/repl.rb', line 10 def listener @listener end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/guard/haskell/repl.rb', line 10 def status @status end |
#stdin ⇒ Object (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
#exit ⇒ Object
46 47 48 49 |
# File 'lib/guard/haskell/repl.rb', line 46 def exit stdin.write(":quit\n") ::Thread.kill(listener) end |
#reload_and_rerun ⇒ Object
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 |