master/lib/guard/interactor.rb

39 lines
927 B
Ruby
Raw Normal View History

2010-10-03 21:00:33 +00:00
module Guard
2011-09-20 11:10:16 +00:00
# The interactor reads user input and triggers
# specific action upon them unless its locked.
#
# Currently the following actions are implemented:
#
2011-09-20 11:10:16 +00:00
# - stop, quit, exit, s, q, e => Exit Guard
# - reload, r, z => Reload Guard
# - pause, p => Pause Guard
# - Everything else => Run all
#
class Interactor
# Start the interactor in its own thread.
2011-09-20 11:10:16 +00:00
#
def start
return if ENV["GUARD_ENV"] == 'test'
2011-09-20 11:10:16 +00:00
@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
end
2010-10-03 21:00:33 +00:00
end
end
end
end
end