diff --git a/Gemfile b/Gemfile index 96997fc..9b6f3c5 100644 --- a/Gemfile +++ b/Gemfile @@ -12,3 +12,6 @@ if Config::CONFIG['target_os'] =~ /linux/i gem 'rb-inotify', '>= 0.5.1', :require => false gem 'libnotify', '~> 0.1.3', :require => false end +if Config::CONFIG['target_os'] =~ /mswin|mingw/i + gem 'win32console' +end diff --git a/lib/guard/interactor.rb b/lib/guard/interactor.rb index 4acd9ed..cea6eb7 100644 --- a/lib/guard/interactor.rb +++ b/lib/guard/interactor.rb @@ -23,19 +23,32 @@ module Guard def self.init_signal_traps # Run all (Ctrl-\) - Signal.trap('QUIT') do - run_all + 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) - Signal.trap('INT') do - stop + 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) - Signal.trap('TSTP') do - reload + 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/lib/guard/ui.rb b/lib/guard/ui.rb index 94953db..fffb40d 100644 --- a/lib/guard/ui.rb +++ b/lib/guard/ui.rb @@ -24,7 +24,11 @@ module Guard end def reset_line - print "\r\e[0m" + if color_enabled? + print "\r\e[0m" + else + print "\r\n" + end end def clear @@ -38,7 +42,27 @@ module Guard end def color(text, color_code) - "#{color_code}#{text}\e[0m" + if color_enabled? + return "#{color_code}#{text}\e[0m" + else + return text + end + end + + def color_enabled? + @color_enabled ||= if Config::CONFIG['target_os'] =~ /mswin|mingw/i + unless ENV['ANSICON'] + begin + require 'rubygems' unless ENV['NO_RUBYGEMS'] + require 'Win32/Console/ANSI' + rescue LoadError + info "You must 'gem install win32console' to use color on Windows" + false + end + end + else + true + end end end