diff options
author | Mark Delk <[email protected]> | 2020-05-17 20:12:02 -0500 |
---|---|---|
committer | git <[email protected]> | 2021-05-24 11:55:58 +0900 |
commit | b8ffb1c46f03dacfdb6b4417274ca66cc9142e5b (patch) | |
tree | d51e44757f8ee11177bc132b7538768b501f46c2 | |
parent | e16a642900b17c18e014360370b4a5eb0897605d (diff) |
[ruby/irb] respect NO_COLOR environment variable
When `NO_COLOR` is set to any non-nil value, output is not colorized.
See https://no-color.org/
https://github.com/ruby/irb/commit/401d0916fe
-rw-r--r-- | lib/irb/init.rb | 4 | ||||
-rw-r--r-- | test/irb/test_init.rb | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/irb/init.rb b/lib/irb/init.rb index 78ef2fa3c1..3a5f3de26c 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] = true + @CONF[:USE_COLORIZE] = !ENV['NO_COLOR'] @CONF[:INSPECT_MODE] = true @CONF[:USE_TRACER] = false @CONF[:USE_LOADER] = false @@ -301,11 +301,11 @@ module IRB # :nodoc: break end end + load_path.collect! do |path| /\A\.\// =~ path ? path : File.expand_path(path) end $LOAD_PATH.unshift(*load_path) - end # running config diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb index d57f0752bb..ade2fcb392 100644 --- a/test/irb/test_init.rb +++ b/test/irb/test_init.rb @@ -67,6 +67,22 @@ module TestIRB Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled? end + def test_no_color_environment_variable + orig = ENV['NO_COLOR'] + + assert IRB.conf[:USE_COLORIZE] + + ENV['NO_COLOR'] = 'true' + IRB.setup(eval("__FILE__")) + refute IRB.conf[:USE_COLORIZE] + + ENV['NO_COLOR'] = nil + IRB.setup(eval("__FILE__")) + assert IRB.conf[:USE_COLORIZE] + ensure + ENV['NO_COLOR'] = orig + end + private def with_argv(argv) |