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

colorize.rb: support for NO_COLOR

This commit is contained in:
Nobuyoshi Nakada 2022-11-01 10:56:28 +09:00
parent f0c8c1e878
commit 99a79dc40b
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

View file

@ -7,7 +7,7 @@ class Colorize
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 color or (color == nil && STDOUT.tty? && (ENV["NO_COLOR"] || "").empty?)
if (%w[smso so].any? {|attr| /\A\e\[.*m\z/ =~ IO.popen("tput #{attr}", "r", :err => IO::NULL, &:read)} rescue nil)
@beg = "\e["
colors = (colors = ENV['TEST_COLORS']) ? Hash[colors.scan(/(\w+)=([^:\n]*)/)] : {}