diff --git a/Guardfile b/Guardfile index 826ffb6..c7cd061 100644 --- a/Guardfile +++ b/Guardfile @@ -1,4 +1,4 @@ -guard 'rspec', :version => 2, :keep_failed => false, :cli => '-f doc' do +guard 'rspec', :version => 2, :all_on_start => false, :all_after_pass => false, :keep_failed => false, :cli => '-f doc' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } diff --git a/lib/guard.rb b/lib/guard.rb index 72a8518..e6cdfab 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -26,7 +26,7 @@ module Guard end def start(options = {}) - Interactor.init_signal_traps + # Interactor.init_signal_traps setup(options) @@ -40,7 +40,9 @@ module Guard UI.info "Guard is now watching at '#{listener.directory}'" guards.each { |guard| supervised_task(guard, :start) } - listener.start + Thread.new { listener.start } + + Interactor.listen end def run_on_change_for_all_guards(files) @@ -78,7 +80,7 @@ module Guard yield rescue Interrupt end - listener.start + Thread.new { listener.start } end def add_guard(name, watchers = [], options = {}) diff --git a/lib/guard/interactor.rb b/lib/guard/interactor.rb index 1170053..000dd3d 100644 --- a/lib/guard/interactor.rb +++ b/lib/guard/interactor.rb @@ -2,53 +2,77 @@ module Guard module Interactor extend self - def run_all - ::Guard.run do - ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) } - end - end - - def stop - UI.info "Bye bye...", :reset => true - ::Guard.listener.stop - ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) } - abort - end - - def reload - ::Guard.run do - ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) } - end - end - - def self.init_signal_traps - # Run all (Ctrl-\) - if Signal.list.has_key?('QUIT') - Signal.trap('QUIT') do - run_all + def listen + return if ENV["GUARD_ENV"] == 'test' + if entry = $stdin.readline + entry.gsub! /\n/, '' + case entry + when 'quit', 'exit', 'q', 'e' + UI.info "Bye bye...", :reset => true + ::Guard.listener.stop + ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) } + abort + when 'reload', 'r', 'z' + ::Guard.run do + ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) } + end + listen + else # run_all + ::Guard.run do + ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) } + end + listen end - else - UI.info "Your system doesn't support QUIT signal, so Ctrl-\\ (Run all) won't work" end - - # Stop (Ctrl-C) - if Signal.list.has_key?('INT') - Signal.trap('INT') do - stop - end - else - UI.info "Your system doesn't support INT signal, so Ctrl-C (Stop) won't work" - end - - # Reload (Ctrl-Z) - if Signal.list.has_key?('TSTP') - Signal.trap('TSTP') do - reload - end - else - UI.info "Your system doesn't support TSTP signal, so Ctrl-Z (Reload) won't work" - end - end + + # def run_all + # ::Guard.run do + # ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) } + # end + # end + # + # def stop + # UI.info "Bye bye...", :reset => true + # ::Guard.listener.stop + # ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) } + # abort + # end + # + # def reload + # ::Guard.run do + # ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) } + # end + # end + # + # def self.init_signal_traps + # # Run all (Ctrl-\) + # if Signal.list.has_key?('QUIT') + # Signal.trap('QUIT') do + # run_all + # end + # else + # UI.info "Your system doesn't support QUIT signal, so Ctrl-\\ (Run all) won't work" + # end + # + # # Stop (Ctrl-C) + # if Signal.list.has_key?('INT') + # Signal.trap('INT') do + # stop + # end + # else + # UI.info "Your system doesn't support INT signal, so Ctrl-C (Stop) won't work" + # end + # + # # Reload (Ctrl-Z) + # if Signal.list.has_key?('TSTP') + # Signal.trap('TSTP') do + # reload + # end + # else + # UI.info "Your system doesn't support TSTP signal, so Ctrl-Z (Reload) won't work" + # end + # + # end end end diff --git a/spec/guard/listener_spec.rb b/spec/guard/listener_spec.rb index e9ae26b..37f6dd6 100644 --- a/spec/guard/listener_spec.rb +++ b/spec/guard/listener_spec.rb @@ -55,10 +55,10 @@ describe Guard::Listener do it "should relativize paths to the configured directory" do subject.relativize_paths(@paths).should =~ %w( a a/b a.b/c.d ) end - + context "when set to false" do subject { described_class.new('/tmp', :relativize_paths => false) } - + it "can be disabled" do subject.relativize_paths(@paths).should eql @paths end @@ -128,7 +128,6 @@ describe Guard::Listener do end describe "working directory" do - context "unspecified" do subject { described_class.new } it "defaults to Dir.pwd" do @@ -158,7 +157,6 @@ describe Guard::Listener do stop end end - end end