aboutsummaryrefslogtreecommitdiffstats
path: root/lib/irb.rb
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2022-06-28 14:30:36 +0100
committergit <svn-admin@ruby-lang.org>2022-06-28 22:30:42 +0900
commit44c1316293f80abaa0e76b3818322544b9372a97 (patch)
treec560d27798f751ab059b4db59de749dbdd09b1de /lib/irb.rb
parent5ccdcd81685cfedd31344690fdb0fd9fc001e3ca (diff)
downloadruby-44c1316293f80abaa0e76b3818322544b9372a97.tar.gz
[ruby/irb] Centralize coloring control (https://github.com/ruby/irb/pull/374)
* Use colorable: argument as the only coloring control * Centalize color controling logic at Color.colorable? There are 2 requirements for coloring output: 1. It's supported on the platform 2. The user wants it: `IRB.conf[:USE_COLORIZE] == true` Right now we check 1 and 2 separately whenever we colorize things. But it's error-prone because while 1 is the default of `colorable` parameter, 2 always need to manually checked. When 2 is overlooked, it causes issues like https://github.com/ruby/irb/pull/362 And there's 0 case where we may want to colorize even when the user disables it. So I think we should merge 2 into `Color.colorable?` so it can be automatically picked up. * Add tests for all inspect modes * Simplify inspectors' coloring logic * Replace use_colorize? with Color.colorable? * Remove Context#use_colorize cause it's redundant https://github.com/ruby/irb/commit/1c53023ac4
Diffstat (limited to 'lib/irb.rb')
-rw-r--r--lib/irb.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index 9d067b7a4d..8e40ffb4d5 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -828,11 +828,11 @@ module IRB
if diff_size.positive? and output_width > winwidth
lines, _ = Reline::Unicode.split_by_width(first_line, winwidth - diff_size - 3)
str = "%s..." % lines.first
- str += "\e[0m" if @context.use_colorize
+ str += "\e[0m" if Color.colorable?
multiline_p = false
else
str = str.gsub(/(\A.*?\n).*/m, "\\1...")
- str += "\e[0m" if @context.use_colorize
+ str += "\e[0m" if Color.colorable?
end
else
output_width = Reline::Unicode.calculate_width(@context.return_format % str, true)
@@ -840,7 +840,7 @@ module IRB
if diff_size.positive? and output_width > winwidth
lines, _ = Reline::Unicode.split_by_width(str, winwidth - diff_size - 3)
str = "%s..." % lines.first
- str += "\e[0m" if @context.use_colorize
+ str += "\e[0m" if Color.colorable?
end
end
end