1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[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
This commit is contained in:
Mark Delk 2020-05-17 20:12:02 -05:00 committed by git
parent e16a642900
commit b8ffb1c46f
2 changed files with 18 additions and 2 deletions

View file

@ -44,7 +44,7 @@ module IRB # :nodoc:
@CONF[:IRB_RC] = nil @CONF[:IRB_RC] = nil
@CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod) @CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
@CONF[:USE_COLORIZE] = true @CONF[:USE_COLORIZE] = !ENV['NO_COLOR']
@CONF[:INSPECT_MODE] = true @CONF[:INSPECT_MODE] = true
@CONF[:USE_TRACER] = false @CONF[:USE_TRACER] = false
@CONF[:USE_LOADER] = false @CONF[:USE_LOADER] = false
@ -301,11 +301,11 @@ module IRB # :nodoc:
break break
end end
end end
load_path.collect! do |path| load_path.collect! do |path|
/\A\.\// =~ path ? path : File.expand_path(path) /\A\.\// =~ path ? path : File.expand_path(path)
end end
$LOAD_PATH.unshift(*load_path) $LOAD_PATH.unshift(*load_path)
end end
# running config # running config

View file

@ -67,6 +67,22 @@ module TestIRB
Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled? Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled?
end 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 private
def with_argv(argv) def with_argv(argv)