summaryrefslogtreecommitdiff
path: root/tool/lib
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2022-12-26 21:57:27 +0900
committerKoichi Sasada <ko1@atdot.net>2022-12-26 23:06:35 +0900
commitc182d46d2477da9283661c8b4544d7da095835b4 (patch)
tree5ba1c07997d41a6325618ad54cc7bfe6e6ecabdd /tool/lib
parent9f2378959e5c5b5c39c9993f1a84e5304ff113d6 (diff)
downloadruby-c182d46d2477da9283661c8b4544d7da095835b4.tar.gz
check `NO_COLOR` envval
Support `NO_COLOR` (https://no-color.org/) to make parsing output easy.
Diffstat (limited to 'tool/lib')
-rw-r--r--tool/lib/colorize.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/tool/lib/colorize.rb b/tool/lib/colorize.rb
index 467cd21246..8fb90e1833 100644
--- a/tool/lib/colorize.rb
+++ b/tool/lib/colorize.rb
@@ -33,9 +33,11 @@ class Colorize
"bold"=>"1", "underline"=>"4", "reverse"=>"7",
}
+ NO_COLOR = (nc = ENV['NO_COLOR']) && !nc.empty?
+
# colorize.decorate(str, name = color_name)
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}"
else
str