From a57d6d2325ddc71363414acf2f923db0bf0ddc9c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 4 Jun 2019 18:08:21 +0900 Subject: colorize.rb: make `colors_file` optional [ci skip] --- tool/colorize.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'tool') 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" -- cgit v1.2.3