From 7d211c93af2253c5f5a4eb988a362f3220965980 Mon Sep 17 00:00:00 2001 From: st0012 Date: Tue, 28 Jun 2022 14:47:28 +0100 Subject: [PATCH] [ruby/irb] Color.colorable? needs to consider the condition when irb is not loaded ruby/debug uses `irb/color` selectively: https://github.com/ruby/debug/blob/0ac22406bb8f65bc76f9f5576a00c729cac693af/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 --- lib/irb/color.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/irb/color.rb b/lib/irb/color.rb index c4513f5b0b..8307af25a9 100644 --- a/lib/irb/color.rb +++ b/lib/irb/color.rb @@ -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)