2010-10-03 21:00:33 +00:00
|
|
|
module Guard
|
|
|
|
module UI
|
|
|
|
class << self
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-06-20 10:13:28 +00:00
|
|
|
color_enabled = nil
|
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
def info(message, options = {})
|
|
|
|
unless ENV["GUARD_ENV"] == "test"
|
|
|
|
reset_line if options[:reset]
|
|
|
|
puts reset_color(message) if message != ''
|
|
|
|
end
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-11-11 10:02:29 +00:00
|
|
|
def error(message, options = {})
|
2010-11-25 23:57:08 +00:00
|
|
|
unless ENV["GUARD_ENV"] == "test"
|
|
|
|
reset_line if options[:reset]
|
2011-06-20 10:13:28 +00:00
|
|
|
puts "#{color('ERROR:', ';31')} #{message}"
|
2010-11-25 23:57:08 +00:00
|
|
|
end
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-11-11 10:02:29 +00:00
|
|
|
def debug(message, options = {})
|
2010-10-10 10:38:25 +00:00
|
|
|
unless ENV["GUARD_ENV"] == "test"
|
2010-11-11 10:02:29 +00:00
|
|
|
reset_line if options[:reset]
|
2010-10-10 10:38:25 +00:00
|
|
|
puts "DEBUG: #{message}" if ::Guard.options && ::Guard.options[:debug]
|
|
|
|
end
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
def reset_line
|
2011-06-20 10:13:28 +00:00
|
|
|
print(color_enabled? ? "\r\e[0m" : "\r\n")
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
def clear
|
|
|
|
system("clear;")
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-10 10:38:25 +00:00
|
|
|
private
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
def reset_color(text)
|
2011-06-20 10:13:28 +00:00
|
|
|
color(text, "")
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
def color(text, color_code)
|
2011-06-20 10:13:28 +00:00
|
|
|
color_enabled? ? "\e[0#{color_code}m#{text}\e[0m" : text
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-05-06 21:35:09 +00:00
|
|
|
def color_enabled?
|
2011-06-20 10:13:28 +00:00
|
|
|
if @color_enabled.nil?
|
|
|
|
if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
|
|
|
|
if ENV['ANSICON']
|
|
|
|
@color_enabled = true
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
|
|
|
require 'Win32/Console/ANSI'
|
|
|
|
@color_enabled = true
|
|
|
|
rescue LoadError
|
|
|
|
@color_enabled = false
|
|
|
|
info "You must 'gem install win32console' to use color on Windows"
|
|
|
|
end
|
2011-05-06 21:35:09 +00:00
|
|
|
end
|
2011-06-20 10:13:28 +00:00
|
|
|
else
|
|
|
|
@color_enabled = true
|
2011-05-06 21:35:09 +00:00
|
|
|
end
|
|
|
|
end
|
2011-06-20 10:13:28 +00:00
|
|
|
@color_enabled
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|