From 70e87d9660af24fb93cac1312b6e1990602c1396 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Thu, 30 May 2019 15:49:48 +0900 Subject: Do not rely on IRB.conf[:MAIN_CONTEXT] before initialize so that we can colorize binding.irb source lines. --- lib/irb/workspace.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb index 9337c172fd..2bbd5cf9ec 100644 --- a/lib/irb/workspace.rb +++ b/lib/irb/workspace.rb @@ -131,7 +131,10 @@ EOF return end end - if IRB.conf&.fetch(:MAIN_CONTEXT, nil)&.use_colorize? + + # NOT using #use_colorize? of IRB.conf[:MAIN_CONTEXT] because this method may be called before IRB::Irb#run + use_colorize = IRB.conf.fetch(:USE_COLORIZE, true) + if use_colorize lines = Color.colorize_code(code).lines else lines = code.lines @@ -141,7 +144,7 @@ EOF start_pos = [pos - 5, 0].max end_pos = [pos + 5, lines.size - 1].min - if IRB.conf&.fetch(:MAIN_CONTEXT, nil)&.use_colorize? + if use_colorize fmt = " %2s #{Color.colorize("%#{end_pos.to_s.length}d", [:BLUE, :BOLD])}: %s" else fmt = " %2s %#{end_pos.to_s.length}d: %s" -- cgit v1.2.3