mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
bdc6d41640
* common.mk (build-ext): pass variables to colorize. * ext/extmk.rb: colorize notes with tool/colorize.rb. * tool/colorize.rb: extract from tool/generic_erb.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
41 lines
877 B
Ruby
41 lines
877 B
Ruby
class Colorize
|
|
def initialize(color = nil)
|
|
@colors = @reset = nil
|
|
if color or (color == nil && STDOUT.tty?)
|
|
if (/\A\e\[.*m\z/ =~ IO.popen("tput smso", "r", err: IO::NULL, &:read) rescue nil)
|
|
@beg = "\e["
|
|
@colors = (colors = ENV['TEST_COLORS']) ? Hash[colors.scan(/(\w+)=([^:\n]*)/)] : {}
|
|
@reset = "#{@beg}m"
|
|
end
|
|
end
|
|
self
|
|
end
|
|
|
|
DEFAULTS = {"pass"=>"32;1", "fail"=>"31;1", "skip"=>"33;1"}
|
|
|
|
def decorate(str, name)
|
|
if @colors and color = (@colors[name] || DEFAULTS[name])
|
|
"#{@beg}#{color}m#{str}#{@reset}"
|
|
else
|
|
str
|
|
end
|
|
end
|
|
|
|
def pass(str)
|
|
decorate(str, "pass")
|
|
end
|
|
|
|
def fail(str)
|
|
decorate(str, "fail")
|
|
end
|
|
|
|
def skip(str)
|
|
decorate(str, "skip")
|
|
end
|
|
end
|
|
|
|
if $0 == __FILE__
|
|
colorize = Colorize.new
|
|
col = ARGV.shift
|
|
ARGV.each {|str| puts colorize.decorate(str, col)}
|
|
end
|