diff --git a/lib/irb/color_printer.rb b/lib/irb/color_printer.rb index 11885f465d..73a150f881 100644 --- a/lib/irb/color_printer.rb +++ b/lib/irb/color_printer.rb @@ -8,7 +8,7 @@ module IRB q = ColorPrinter.new(out, width) q.guard_inspect_key {q.pp obj} q.flush - out + out << "\n" end def text(str, width = nil) diff --git a/lib/irb/inspector.rb b/lib/irb/inspector.rb index 92de2830bc..c2f3b605db 100644 --- a/lib/irb/inspector.rb +++ b/lib/irb/inspector.rb @@ -116,7 +116,7 @@ module IRB # :nodoc: } Inspector.def_inspector([true, :pp, :pretty_inspect], proc{require "irb/color_printer"}){|v| if IRB.conf[:MAIN_CONTEXT]&.use_colorize? - IRB::ColorPrinter.pp(v, '') + IRB::ColorPrinter.pp(v, '').chomp else v.pretty_inspect.chomp end diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb index 6ce652104b..203b605296 100644 --- a/test/irb/test_color.rb +++ b/test/irb/test_color.rb @@ -158,9 +158,9 @@ module TestIRB skip 'Ripper::Lexer#scan is supported in Ruby 2.7+' end { - 1 => "#{BLUE}#{BOLD}1#{CLEAR}", - Struct.new('IRBTestColorPrinter', :a).new('test') => "#{GREEN}##{CLEAR}", - Ripper::Lexer.new('1').scan => "[#{GREEN}##{CLEAR}]", + 1 => "#{BLUE}#{BOLD}1#{CLEAR}\n", + Struct.new('IRBTestColorPrinter', :a).new('test') => "#{GREEN}##{CLEAR}\n", + Ripper::Lexer.new('1').scan => "[#{GREEN}##{CLEAR}]\n", }.each do |object, result| actual = with_term { IRB::ColorPrinter.pp(object, '') } assert_equal(result, actual, "Case: IRB::ColorPrinter.pp(#{object.inspect}, '')")