support color on windows
This commit is contained in:
parent
cbe2cb353c
commit
6ecb72c9cb
3
Gemfile
3
Gemfile
@ -12,3 +12,6 @@ if Config::CONFIG['target_os'] =~ /linux/i
|
||||
gem 'rb-inotify', '>= 0.5.1'
|
||||
gem 'libnotify', '~> 0.1.3'
|
||||
end
|
||||
if Config::CONFIG['target_os'] =~ /mswin|mingw/i
|
||||
gem 'win32console'
|
||||
end
|
||||
|
@ -2,6 +2,29 @@ module Guard
|
||||
module UI
|
||||
class << self
|
||||
|
||||
@color_enabled = true
|
||||
@color_tested = false
|
||||
@new_line = "\r"
|
||||
|
||||
def color_enabled?
|
||||
if !@color_tested
|
||||
@color_tested = true
|
||||
if Config::CONFIG['target_os'] =~ /mswin|mingw/i
|
||||
@new_line = "\r\n"
|
||||
unless ENV['ANSICON']
|
||||
begin
|
||||
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
||||
require 'Win32/Console/ANSI'
|
||||
rescue LoadError
|
||||
@color_enabled = false
|
||||
info "You must 'gem install win32console' to use color on Windows"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return @color_enabled
|
||||
end
|
||||
|
||||
def info(message, options = {})
|
||||
unless ENV["GUARD_ENV"] == "test"
|
||||
reset_line if options[:reset]
|
||||
@ -24,7 +47,11 @@ module Guard
|
||||
end
|
||||
|
||||
def reset_line
|
||||
print "\r\e[0m"
|
||||
if color_enabled?
|
||||
print @new_line + "\e[0m"
|
||||
else
|
||||
print @new_line
|
||||
end
|
||||
end
|
||||
|
||||
def clear
|
||||
@ -38,7 +65,11 @@ 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
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user