[ruby/irb] Color.colorable? needs to consider the condition when irb is not loaded

ruby/debug uses `irb/color` selectively:
0ac22406bb/lib/debug/color.rb (L4)

And in that case, `IRB.conf` won't be defined. So Color.colorable? needs
to consider that.

This also fixes the Ruby trunk CI.

https://github.com/ruby/irb/commit/b2cd07e795
This commit is contained in:
st0012 2022-06-28 14:47:28 +01:00 committed by git
parent 44c1316293
commit 7d211c93af

View File

@ -77,7 +77,15 @@ module IRB # :nodoc:
class << self
def colorable?
$stdout.tty? && (/mswin|mingw/ =~ RUBY_PLATFORM || (ENV.key?('TERM') && ENV['TERM'] != 'dumb')) && IRB.conf.fetch(:USE_COLORIZE, true)
supported = $stdout.tty? && (/mswin|mingw/ =~ RUBY_PLATFORM || (ENV.key?('TERM') && ENV['TERM'] != 'dumb'))
# because ruby/debug also uses irb's color module selectively,
# irb won't be activated in that case.
if IRB.respond_to?(:conf)
supported && IRB.conf.fetch(:USE_COLORIZE, true)
else
supported
end
end
def inspect_colorable?(obj, seen: {}.compare_by_identity)