diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-08-11 16:17:51 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-08-11 18:35:07 +0900 |
commit | 2e7fe3b687b8bad1452b7643c0063b89c91c930a (patch) | |
tree | 541e3ea4e955e064757ac6a2ca4923d916e3ed60 /tool | |
parent | 5af983af4f7722845f73b426cb33b7ba91a1c47c (diff) |
Add default color for each instance
Diffstat (limited to 'tool')
-rw-r--r-- | tool/lib/colorize.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/tool/lib/colorize.rb b/tool/lib/colorize.rb index 7494a2198a..6699aef572 100644 --- a/tool/lib/colorize.rb +++ b/tool/lib/colorize.rb @@ -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 |