Skip to content

Commit

Permalink
[ruby/irb] Check colorize option correctly to clear char attr and don…
Browse files Browse the repository at this point in the history
…'t use it for tests

ruby/irb@de561cafeb
  • Loading branch information
aycabta authored and matzbot committed Dec 21, 2021
1 parent 093aaef commit 1855f90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/irb.rb
Expand Up @@ -824,17 +824,20 @@ def output_value(omit = false) # :nodoc:
diff_size = output_width - Reline::Unicode.calculate_width(first_line, true)
if diff_size.positive? and output_width > winwidth
lines, _ = Reline::Unicode.split_by_width(first_line, winwidth - diff_size - 3)
str = "%s...\e[0m" % lines.first
str = "%s..." % lines.first
str += "\e[0m" if @context.use_colorize
multiline_p = false
else
str = str.gsub(/(\A.*?\n).*/m, "\\1...\e[0m")
str = str.gsub(/(\A.*?\n).*/m, "\\1...")
str += "\e[0m" if @context.use_colorize
end
else
output_width = Reline::Unicode.calculate_width(@context.return_format % str, true)
diff_size = output_width - Reline::Unicode.calculate_width(str, true)
if diff_size.positive? and output_width > winwidth
lines, _ = Reline::Unicode.split_by_width(str, winwidth - diff_size - 3)
str = "%s...\e[0m" % lines.first
str = "%s..." % lines.first
str += "\e[0m" if @context.use_colorize
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion test/irb/test_context.rb
Expand Up @@ -259,6 +259,7 @@ def test_echo_on_assignment
end

def test_omit_on_assignment
IRB.conf[:USE_COLORIZE] = false
input = TestInputMethod.new([
"a = [1] * 100\n",
"a\n",
Expand Down Expand Up @@ -322,6 +323,7 @@ def test_omit_on_assignment
end

def test_omit_multiline_on_assignment
IRB.conf[:USE_COLORIZE] = false
input = TestInputMethod.new([
"class A; def inspect; ([?* * 1000] * 3).join(%{\\n}); end; end; a = A.new\n",
"a\n"
Expand All @@ -347,7 +349,7 @@ def test_omit_multiline_on_assignment
irb.eval_input
end
assert_empty err
assert_equal("=> #{value_first_line[0..(input.winsize.last - 9)]}...\e[0m\n=> \n#{value}\n", out)
assert_equal("=> #{value_first_line[0..(input.winsize.last - 9)]}...\n=> \n#{value}\n", out)
irb.context.evaluate('A.remove_method(:inspect)', 0)

input.reset
Expand Down Expand Up @@ -395,6 +397,7 @@ def test_echo_on_assignment_conf
# Default
IRB.conf[:ECHO] = nil
IRB.conf[:ECHO_ON_ASSIGNMENT] = nil
IRB.conf[:USE_COLORIZE] = false
input = TestInputMethod.new()
irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)

Expand Down Expand Up @@ -422,6 +425,7 @@ def test_multiline_output_on_default_inspector
def main.inspect
"abc\ndef"
end
IRB.conf[:USE_COLORIZE] = false
input = TestInputMethod.new([
"self"
])
Expand Down

0 comments on commit 1855f90

Please sign in to comment.