First trial to remove Posix Signals interaction

This commit is contained in:
Thibaud Guillaume-Gentil 2011-08-13 16:43:32 +02:00
parent ca4b808b86
commit 573ddf9d9d
4 changed files with 77 additions and 53 deletions

View File

@ -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{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" } watch('spec/spec_helper.rb') { "spec" }

View File

@ -26,7 +26,7 @@ module Guard
end end
def start(options = {}) def start(options = {})
Interactor.init_signal_traps # Interactor.init_signal_traps
setup(options) setup(options)
@ -40,7 +40,9 @@ module Guard
UI.info "Guard is now watching at '#{listener.directory}'" UI.info "Guard is now watching at '#{listener.directory}'"
guards.each { |guard| supervised_task(guard, :start) } guards.each { |guard| supervised_task(guard, :start) }
listener.start Thread.new { listener.start }
Interactor.listen
end end
def run_on_change_for_all_guards(files) def run_on_change_for_all_guards(files)
@ -78,7 +80,7 @@ module Guard
yield yield
rescue Interrupt rescue Interrupt
end end
listener.start Thread.new { listener.start }
end end
def add_guard(name, watchers = [], options = {}) def add_guard(name, watchers = [], options = {})

View File

@ -2,53 +2,77 @@ module Guard
module Interactor module Interactor
extend self extend self
def run_all def listen
::Guard.run do return if ENV["GUARD_ENV"] == 'test'
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) } if entry = $stdin.readline
end entry.gsub! /\n/, ''
end case entry
when 'quit', 'exit', 'q', 'e'
def stop UI.info "Bye bye...", :reset => true
UI.info "Bye bye...", :reset => true ::Guard.listener.stop
::Guard.listener.stop ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) }
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) } abort
abort when 'reload', 'r', 'z'
end ::Guard.run do
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) }
def reload end
::Guard.run do listen
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) } else # run_all
end ::Guard.run do
end ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) }
end
def self.init_signal_traps listen
# Run all (Ctrl-\)
if Signal.list.has_key?('QUIT')
Signal.trap('QUIT') do
run_all
end end
else
UI.info "Your system doesn't support QUIT signal, so Ctrl-\\ (Run all) won't work"
end 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
# 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
end end

View File

@ -128,7 +128,6 @@ describe Guard::Listener do
end end
describe "working directory" do describe "working directory" do
context "unspecified" do context "unspecified" do
subject { described_class.new } subject { described_class.new }
it "defaults to Dir.pwd" do it "defaults to Dir.pwd" do
@ -158,7 +157,6 @@ describe Guard::Listener do
stop stop
end end
end end
end end
end end