master/lib/guard/ui.rb

71 lines
1.5 KiB
Ruby
Raw Normal View History

2010-10-03 21:00:33 +00:00
module Guard
module UI
class << self
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
2010-11-11 10:02:29 +00:00
def error(message, options = {})
unless ENV["GUARD_ENV"] == "test"
reset_line if options[:reset]
puts "ERROR: #{message}"
end
2010-10-03 21:00:33 +00:00
end
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
2010-10-03 21:00:33 +00:00
def reset_line
if color_enabled?
print "\r\e[0m"
2011-04-24 19:30:54 +00:00
else
print "\r\n"
2011-04-24 19:30:54 +00:00
end
2010-10-03 21:00:33 +00:00
end
2010-10-03 21:00:33 +00:00
def clear
system("clear;")
end
2010-10-10 10:38:25 +00:00
private
2010-10-03 21:00:33 +00:00
def reset_color(text)
color(text, "\e[0m")
end
2010-10-03 21:00:33 +00:00
def color(text, color_code)
2011-04-24 19:30:54 +00:00
if color_enabled?
return "#{color_code}#{text}\e[0m"
else
return text
end
2010-10-03 21:00:33 +00:00
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
2010-10-03 21:00:33 +00:00
end
2010-10-03 21:00:33 +00:00
end
end
end