1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

colorize.rb: get rid of syntax errors on older versions

This commit is contained in:
Nobuyoshi Nakada 2019-06-04 18:10:09 +09:00
parent a57d6d2325
commit fade26afa7
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60

View file

@ -1,13 +1,13 @@
# frozen-string-literal: true
class Colorize
def initialize(color = nil, colors_file: nil)
def initialize(color = nil, opts = ((_, color = color, nil)[0] if Hash === color))
@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)
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]*)/)] : {}
if colors_file
if opts and colors_file = opts[:colors_file]
begin
File.read(colors_file).scan(/(\w+)=([^:\n]*)/) do |n, c|
colors[n] ||= c