fix issue where interator thread was continuing to capture input from stdin while a guard is being executed

This commit is contained in:
Brian John 2011-10-02 16:46:20 -05:00
parent b3535b4a4e
commit cd545d5207
2 changed files with 25 additions and 16 deletions

View File

@ -29,6 +29,8 @@ module Guard
# @option options [Boolean] watch_all_modifications watches all file modifications if true
#
def setup(options = {})
@lock = Mutex.new
@options = options
@guards = []
@groups = [Group.new(:default)]
@ -41,8 +43,6 @@ module Guard
debug_command_execution if @options[:debug]
@lock = Mutex.new
self
end
@ -180,9 +180,12 @@ module Guard
@lock.synchronize do
begin
@interactor.stop_if_not_current
yield
rescue Interrupt
end
@interactor.start
end
end

View File

@ -11,28 +11,34 @@ module Guard
# - Everything else => Run all
#
class Interactor
# Start the interactor in its own thread.
#
def start
return if ENV["GUARD_ENV"] == 'test'
@thread = Thread.new do
while entry = $stdin.gets.chomp
entry.gsub! /\n/, ''
case entry
when 'stop', 'quit', 'exit', 's', 'q', 'e'
::Guard.stop
when 'reload', 'r', 'z'
::Guard::Dsl.reevaluate_guardfile
::Guard.reload
when 'pause', 'p'
::Guard.pause
else
::Guard.run_all
if !@thread || @thread.stop?
@thread = Thread.new do
while entry = $stdin.gets.chomp
case entry
when 'stop', 'quit', 'exit', 's', 'q', 'e'
::Guard.stop
when 'reload', 'r', 'z'
::Guard::Dsl.reevaluate_guardfile
::Guard.reload
when 'pause', 'p'
::Guard.pause
else
::Guard.run_all
end
end
end
end
end
def stop_if_not_current
unless Thread.current == @thread
@thread.kill
end
end
end
end