Merge branch 'master' of https://github.com/stereobooster/guard into stereobooster-master

Conflicts:
	lib/guard/ui.rb
This commit is contained in:
Rémy Coutable 2011-07-25 23:28:54 +02:00
commit 9b711ea7fb

View File

@ -1,32 +1,55 @@
module Guard module Guard
module UI module UI
ANSI_ESCAPE_BRIGHT = "1"
ANSI_ESCAPE_BLACK = "30"
ANSI_ESCAPE_RED = "31"
ANSI_ESCAPE_GREEN = "32"
ANSI_ESCAPE_YELLOW = "33"
ANSI_ESCAPE_BLUE = "34"
ANSI_ESCAPE_MAGENTA = "35"
ANSI_ESCAPE_CYAN = "36"
ANSI_ESCAPE_WHITE = "37"
ANSI_ESCAPE_BGBLACK = "40"
ANSI_ESCAPE_BGRED = "41"
ANSI_ESCAPE_BGGREEN = "42"
ANSI_ESCAPE_BGYELLOW = "43"
ANSI_ESCAPE_BGBLUE = "44"
ANSI_ESCAPE_BGMAGENTA = "45"
ANSI_ESCAPE_BGCYAN = "46"
ANSI_ESCAPE_BGWHITE = "47"
class << self class << self
color_enabled = nil
def info(message, options = {}) def info(message, options = {})
unless ENV["GUARD_ENV"] == "test" unless ENV["GUARD_ENV"] == "test"
reset_line if options[:reset] reset_line if options[:reset]
puts reset_color(message) if message != '' puts color(message) if message != ''
end end
end end
def error(message, options = {}) def error(message, options = {})
unless ENV["GUARD_ENV"] == "test" unless ENV["GUARD_ENV"] == "test"
reset_line if options[:reset] reset_line if options[:reset]
puts "#{color('ERROR:', ';31')} #{message}" puts color('ERROR: ', :red) + message
end end
end end
def deprecation(message, options = {}) def deprecation(message, options = {})
unless ENV["GUARD_ENV"] == "test" unless ENV["GUARD_ENV"] == "test"
reset_line if options[:reset] reset_line if options[:reset]
puts "#{color('DEPRECATION:', ';31')} #{message}" puts color('DEPRECATION: ', :red) + message
end end
end end
def debug(message, options = {}) def debug(message, options = {})
unless ENV["GUARD_ENV"] == "test" unless ENV["GUARD_ENV"] == "test"
reset_line if options[:reset] reset_line if options[:reset]
puts "DEBUG (#{Time.now.strftime('%T')}): #{message}" if ::Guard.options && ::Guard.options[:debug] puts color("DEBUG (#{Time.now.strftime('%T')}): ", :yellow) + message if ::Guard.options && ::Guard.options[:debug]
end end
end end
@ -40,29 +63,46 @@ module Guard
private private
# @deprecated
def reset_color(text) def reset_color(text)
deprecation('UI.reset_color(text) is deprecated, please use color(text, "") instead.')
color(text, "") color(text, "")
end end
def color(text, color_code) def color(text, *color_options)
color_code = ""
color_options.each do |color_option|
color_option = color_option.to_s
if color_option != ""
if !(color_option =~ /\d+/)
color_option = const_get("ANSI_ESCAPE_#{color_option.upcase}")
end
color_code += ";" + color_option
end
end
color_enabled? ? "\e[0#{color_code}m#{text}\e[0m" : text color_enabled? ? "\e[0#{color_code}m#{text}\e[0m" : text
end end
def color_enabled? def color_enabled?
@color_enabled ||= if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i if @color_enabled.nil?
unless ENV['ANSICON'] if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
begin if ENV['ANSICON']
require 'rubygems' unless ENV['NO_RUBYGEMS'] @color_enabled = true
require 'Win32/Console/ANSI' else
rescue LoadError begin
@color_enabled = false require 'rubygems' unless ENV['NO_RUBYGEMS']
info "You must 'gem install win32console' to use color on Windows" require 'Win32/Console/ANSI'
false @color_enabled = true
rescue LoadError
@color_enabled = false
info "You must 'gem install win32console' to use color on Windows"
end
end end
else
@color_enabled = true
end end
else
true
end end
@color_enabled
end end
end end