diff options
author | aycabta <aycabta@gmail.com> | 2019-05-15 16:36:33 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2019-05-21 08:57:21 +0900 |
commit | 3a9008b9845db544d0788851f9527ce9f9f6bf4a (patch) | |
tree | 0bc7cd93696f1a57b2d25e6a72df71bde72ecf44 /lib/irb/workspace.rb | |
parent | df6a673ca55d26a768ead23466c7e055a8596d7a (diff) | |
download | ruby-3a9008b9845db544d0788851f9527ce9f9f6bf4a.tar.gz |
Add --colorize and --nocolorize options to IRB
Diffstat (limited to 'lib/irb/workspace.rb')
-rw-r--r-- | lib/irb/workspace.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb index c23668b998..bb7407aa0f 100644 --- a/lib/irb/workspace.rb +++ b/lib/irb/workspace.rb @@ -131,13 +131,17 @@ EOF return end end - lines = Color.colorize_code(code).lines + lines = IRB.conf[:MAIN_CONTEXT]&.use_colorize? ? Color.colorize_code(code).lines : code.lines pos -= 1 start_pos = [pos - 5, 0].max end_pos = [pos + 5, lines.size - 1].min - fmt = " %2s #{Color.colorize("%#{end_pos.to_s.length}d", [:BLUE, :BOLD])}: %s" + if IRB.conf[:MAIN_CONTEXT]&.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" + end body = (start_pos..end_pos).map do |current_pos| sprintf(fmt, pos == current_pos ? '=>' : '', current_pos + 1, lines[current_pos]) end.join("") |