diff options
Diffstat (limited to 'tool')
-rw-r--r-- | tool/colorize.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/tool/colorize.rb b/tool/colorize.rb index ed79858ba4..92ed2b5765 100644 --- a/tool/colorize.rb +++ b/tool/colorize.rb @@ -1,17 +1,19 @@ # frozen-string-literal: true class Colorize - def initialize(color = nil) + def initialize(color = nil, colors_file: 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]*)/)] : {} - begin - File.read(File.join(__dir__, "../test/colors")).scan(/(\w+)=([^:\n]*)/) do |n, c| - colors[n] ||= c + if colors_file + begin + File.read(colors_file).scan(/(\w+)=([^:\n]*)/) do |n, c| + colors[n] ||= c + end + rescue Errno::ENOENT end - rescue Errno::ENOENT end @colors = colors @reset = "#{@beg}m" |