diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-06-04 18:08:21 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-06-04 18:08:35 +0900 |
commit | a57d6d2325ddc71363414acf2f923db0bf0ddc9c (patch) | |
tree | 61d1f47b20be8846c32fbea1cd18eb6581ff318e /tool/colorize.rb | |
parent | b0c35ff2db3a4ebb12a405705592e938f50bff64 (diff) | |
download | ruby-a57d6d2325ddc71363414acf2f923db0bf0ddc9c.tar.gz |
colorize.rb: make `colors_file` optional
[ci skip]
Diffstat (limited to 'tool/colorize.rb')
-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" |