diff options
author | Koichi Sasada <ko1@atdot.net> | 2022-12-26 21:57:27 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2022-12-26 23:06:35 +0900 |
commit | c182d46d2477da9283661c8b4544d7da095835b4 (patch) | |
tree | 5ba1c07997d41a6325618ad54cc7bfe6e6ecabdd /tool | |
parent | 9f2378959e5c5b5c39c9993f1a84e5304ff113d6 (diff) |
check `NO_COLOR` envval
Support `NO_COLOR` (https://no-color.org/) to make parsing output easy.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7030
Diffstat (limited to 'tool')
-rw-r--r-- | tool/lib/colorize.rb | 4 |
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 |