summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-10-28 18:30:20 +0900
committergit <svn-admin@ruby-lang.org>2022-10-28 09:30:24 +0000
commit56c97a6621241db99f7c96740164bdd8f898d881 (patch)
treef308631bbdf724b1dd30b9fd6c2538e21265af39
parent13e968c1cdd2da470173e2cc15b44ebb936be534 (diff)
[ruby/irb] Update regarding NO_COLOR value
https://no-color.org has been updated (jcs/no_color#83): > Command-line software which adds ANSI color to its output by default should check for a `NO_COLOR` environment variable that, when present and **not an empty string** (regardless of its value), prevents the addition of ANSI color. https://github.com/ruby/irb/commit/46e0f7e370 Co-authored-by: Stan Lo <stan001212@gmail.com>
-rw-r--r--lib/irb/init.rb2
-rw-r--r--test/irb/test_init.rb4
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index d9c4353f39..11d10c5bab 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -44,7 +44,7 @@ module IRB # :nodoc:
@CONF[:IRB_RC] = nil
@CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
- @CONF[:USE_COLORIZE] = !ENV['NO_COLOR']
+ @CONF[:USE_COLORIZE] = (nc = ENV['NO_COLOR']).nil? || nc.empty?
@CONF[:USE_AUTOCOMPLETE] = true
@CONF[:INSPECT_MODE] = true
@CONF[:USE_TRACER] = false
diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb
index 3293b98d34..074aae4070 100644
--- a/test/irb/test_init.rb
+++ b/test/irb/test_init.rb
@@ -80,6 +80,10 @@ module TestIRB
IRB.setup(__FILE__)
refute IRB.conf[:USE_COLORIZE]
+ ENV['NO_COLOR'] = ''
+ IRB.setup(__FILE__)
+ assert IRB.conf[:USE_COLORIZE]
+
ENV['NO_COLOR'] = nil
IRB.setup(__FILE__)
assert IRB.conf[:USE_COLORIZE]