зеркало из https://github.com/github/ruby.git
Add default color for each instance
This commit is contained in:
Родитель
5af983af4f
Коммит
2e7fe3b687
|
@ -1,8 +1,12 @@
|
|||
# frozen-string-literal: true
|
||||
|
||||
class Colorize
|
||||
# call-seq:
|
||||
# Colorize.new(colorize = nil)
|
||||
# Colorize.new(color: color, colors_file: colors_file)
|
||||
def initialize(color = nil, opts = ((_, color = color, nil)[0] if Hash === color))
|
||||
@colors = @reset = nil
|
||||
@color = (opts[:color] if opts)
|
||||
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["
|
||||
|
@ -29,7 +33,8 @@ class Colorize
|
|||
"bold"=>"1", "underline"=>"4", "reverse"=>"7",
|
||||
}
|
||||
|
||||
def decorate(str, name)
|
||||
# colorize.decorate(str, name = color_name)
|
||||
def decorate(str, name = @color)
|
||||
if @colors and color = (@colors[name] || DEFAULTS[name])
|
||||
"#{@beg}#{color}m#{str}#{@reset}"
|
||||
else
|
||||
|
@ -45,7 +50,6 @@ class Colorize
|
|||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
colorize = Colorize.new
|
||||
col = ARGV.shift
|
||||
ARGV.each {|str| puts colorize.decorate(str, col)}
|
||||
colorize = Colorize.new(ARGV.shift)
|
||||
ARGV.each {|str| puts colorize.decorate(str)}
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче