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

ruby-changes:55974

From: Takashi <ko1@a...>
Date: Tue, 4 Jun 2019 00:27:09 +0900 (JST)
Subject: [ruby-changes:55974] Takashi Kokubun: de541fe196 (trunk): colorize_code must return escaped text

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

From de541fe1961370e64541d73c96cf790d30f28604 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Tue, 4 Jun 2019 00:22:22 +0900
Subject: colorize_code must return escaped text

This was needed before 0c459af7c233adb5f44022350bfe8fa132d8053e but it
could be actually useless now. But I added this anyway just in case.

diff --git a/lib/irb/color.rb b/lib/irb/color.rb
index c2d0084..4996ccf 100644
--- a/lib/irb/color.rb
+++ b/lib/irb/color.rb
@@ -123,7 +123,9 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L123
         end
 
         # give up colorizing incomplete Ripper tokens
-        return code if length != code.bytesize
+        if length != code.bytesize
+          return Reline::Unicode.escape_for_print(code)
+        end
 
         colored
       end
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index d327d61..ae6e02a 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -69,6 +69,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L69
         "\t" => "\t", # not ^I
         "foo(*%W(bar))" => "foo(*#{RED}%W(#{CLEAR}#{RED}bar#{CLEAR}#{RED})#{CLEAR})",
         "$stdout" => "#{GREEN}#{BOLD}$stdout#{CLEAR}",
+        "\u0013" => "#{RED}#{REVERSE}^S#{CLEAR}",
       }.each do |code, result|
         actual = with_term { IRB::Color.colorize_code(code, complete: true) }
         assert_equal(result, actual, "Case: colorize_code(#{code.dump}, complete: true)\nResult: #{humanized_literal(actual)}")
@@ -79,7 +80,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L80
     end
 
     def test_colorize_code_complete_true
-      # `complete: true` behaviors. Warn end-of-file.
+      # `complete: true` behaviors. Warn compile_error.
       {
         "'foo' + 'bar" => "#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR} + #{RED}'#{CLEAR}#{RED}#{REVERSE}bar#{CLEAR}",
       }.each do |code, result|
@@ -89,7 +90,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L90
     end
 
     def test_colorize_code_complete_false
-      # `complete: false` behaviors. Do not warn end-of-file
+      # `complete: false` behaviors. Do not warn compile_error.
       {
         "'foo' + 'bar" => "#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR} + #{RED}'#{CLEAR}#{RED}bar#{CLEAR}",
       }.each do |code, result|
-- 
cgit v0.10.2


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

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