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

Do not rely on IRB.conf[:MAIN_CONTEXT] before initialize

so that we can colorize binding.irb source lines.
This commit is contained in:
Takashi Kokubun 2019-05-30 15:49:48 +09:00
parent 55c34b994b
commit 70e87d9660
No known key found for this signature in database
GPG key ID: 6FFC433B12EE23DD

View file

@ -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"