[前][次][番号順一覧][スレッド一覧]

ruby-changes:64800

From: Takashi <ko1@a...>
Date: Fri, 8 Jan 2021 15:44:07 +0900 (JST)
Subject: [ruby-changes:64800] 98bd7e87a0 (master): [ruby/irb] Make IRB::ColorPrinter.pp compatible with PP.pp

https://git.ruby-lang.org/ruby.git/commit/?id=98bd7e87a0

From 98bd7e87a08b86c7aa95502428015c3f7b4aae75 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Thu, 7 Jan 2021 22:41:58 -0800
Subject: [ruby/irb] Make IRB::ColorPrinter.pp compatible with PP.pp

The incompatible interface is not helpful, again if you want to use it
as a standalone library, falling it back to PP.

Original PP.pp also ends with `out << "\n"`.

https://github.com/ruby/irb/commit/4c74c7d84c

diff --git a/lib/irb/color_printer.rb b/lib/irb/color_printer.rb
index 11885f4..73a150f 100644
--- a/lib/irb/color_printer.rb
+++ b/lib/irb/color_printer.rb
@@ -8,7 +8,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/color_printer.rb#L8
       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 92de283..c2f3b60 100644
--- a/lib/irb/inspector.rb
+++ b/lib/irb/inspector.rb
@@ -116,7 +116,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/inspector.rb#L116
   }
   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 6ce6521..203b605 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -158,9 +158,9 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L158
         skip 'Ripper::Lexer#scan is supported in Ruby 2.7+'
       end
       {
-        1 => "#{BLUE}#{BOLD}1#{CLEAR}",
-        Struct.new('IRBTestColorPrinter', :a).new('test') => "#{GREEN}#<struct Struct::IRBTestColorPrinter#{CLEAR} a#{GREEN}=#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{RED}test#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{GREEN}>#{CLEAR}",
-        Ripper::Lexer.new('1').scan => "[#{GREEN}#<Ripper::Lexer::Elem:#{CLEAR} on_int@1:0 END token: #{RED}#{BOLD}\"#{CLEAR}#{RED}1#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{GREEN}>#{CLEAR}]",
+        1 => "#{BLUE}#{BOLD}1#{CLEAR}\n",
+        Struct.new('IRBTestColorPrinter', :a).new('test') => "#{GREEN}#<struct Struct::IRBTestColorPrinter#{CLEAR} a#{GREEN}=#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{RED}test#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{GREEN}>#{CLEAR}\n",
+        Ripper::Lexer.new('1').scan => "[#{GREEN}#<Ripper::Lexer::Elem:#{CLEAR} on_int@1:0 END token: #{RED}#{BOLD}\"#{CLEAR}#{RED}1#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{GREEN}>#{CLEAR}]\n",
       }.each do |object, result|
         actual = with_term { IRB::ColorPrinter.pp(object, '') }
         assert_equal(result, actual, "Case: IRB::ColorPrinter.pp(#{object.inspect}, '')")
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]