mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 21:49:06 +02:00
check NO_COLOR
envval
Support `NO_COLOR` (https://no-color.org/) to make parsing output easy.
This commit is contained in:
parent
9f2378959e
commit
c182d46d24
Notes:
git
2022-12-26 14:06:53 +00:00
1 changed files with 3 additions and 1 deletions
|
@ -33,9 +33,11 @@ class Colorize
|
||||||
"bold"=>"1", "underline"=>"4", "reverse"=>"7",
|
"bold"=>"1", "underline"=>"4", "reverse"=>"7",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NO_COLOR = (nc = ENV['NO_COLOR']) && !nc.empty?
|
||||||
|
|
||||||
# colorize.decorate(str, name = color_name)
|
# colorize.decorate(str, name = color_name)
|
||||||
def decorate(str, name = @color)
|
def decorate(str, name = @color)
|
||||||
if @colors and color = (@colors[name] || DEFAULTS[name])
|
if !NO_COLOR and @colors and color = (@colors[name] || DEFAULTS[name])
|
||||||
"#{@beg}#{color}m#{str}#{@reset}"
|
"#{@beg}#{color}m#{str}#{@reset}"
|
||||||
else
|
else
|
||||||
str
|
str
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue