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

ruby-changes:55843

From: Takashi <ko1@a...>
Date: Sun, 26 May 2019 14:29:45 +0900 (JST)
Subject: [ruby-changes:55843] Takashi Kokubun: 52b09fcee1 (trunk): Deal with more syntax highlight edge cases

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

From 52b09fcee1b170ad3be7d26b885b8a509c7ba006 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Sat, 25 May 2019 22:29:16 -0700
Subject: Deal with more syntax highlight edge cases

Please refer to the tests again.

diff --git a/lib/irb/color.rb b/lib/irb/color.rb
index 269b122..2439bc7 100644
--- a/lib/irb/color.rb
+++ b/lib/irb/color.rb
@@ -15,12 +15,13 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L15
     CYAN      = 36
 
     TOKEN_KEYWORDS = {
-      on_kw: ['nil', 'self', 'true', 'false', '__FILE__'],
+      on_kw: ['nil', 'self', 'true', 'false', '__FILE__', '__LINE__'],
       on_const: ['ENV'],
     }
 
     begin
       TOKEN_SEQ_EXPRS = {
+        on_backtick:        [[RED],                   [Ripper::EXPR_BEG]],
         on_CHAR:            [[BLUE, BOLD],            [Ripper::EXPR_END]],
         on_const:           [[BLUE, BOLD, UNDERLINE], [Ripper::EXPR_ARG, Ripper::EXPR_CMDARG, Ripper::EXPR_ENDFN]],
         on_embexpr_beg:     [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_CMDARG, Ripper::EXPR_FNAME, Ripper::EXPR_ARG]],
@@ -42,6 +43,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L43
         on_tstring_beg:     [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]],
         on_tstring_content: [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG, Ripper::EXPR_FNAME]],
         on_tstring_end:     [[RED],                   [Ripper::EXPR_END]],
+        on_words_beg:       [[RED],                   [Ripper::EXPR_BEG]],
       }
     rescue NameError
       TOKEN_SEQ_EXPRS = {}
diff --git a/lib/reline/unicode.rb b/lib/reline/unicode.rb
index b12c204..448bdf1 100644
--- a/lib/reline/unicode.rb
+++ b/lib/reline/unicode.rb
@@ -58,7 +58,7 @@ class Reline::Unicode https://github.com/ruby/ruby/blob/trunk/lib/reline/unicode.rb#L58
   def self.escape_for_print(str)
     str.chars.map! { |gr|
       escaped = EscapedPairs[gr.ord]
-      if escaped && gr != "\n"
+      if escaped && gr != -"\n" && gr != -"\t"
         escaped
       else
         gr
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index 9d87b71..eb30840 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -46,7 +46,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L46
         '"#{}"' => "#{RED}\"#{CLEAR}#{RED}\#{#{CLEAR}#{RED}}#{CLEAR}#{RED}\"#{CLEAR}",
         ':"a#{}b"' => "#{YELLOW}:\"#{CLEAR}#{YELLOW}a#{CLEAR}#{YELLOW}\#{#{CLEAR}#{YELLOW}}#{CLEAR}#{YELLOW}b#{CLEAR}#{YELLOW}\"#{CLEAR}",
         ':"a#{ def b; end; \'c\' + "#{ :d }" }e"' => "#{YELLOW}:\"#{CLEAR}#{YELLOW}a#{CLEAR}#{YELLOW}\#{#{CLEAR} #{GREEN}def#{CLEAR} #{BLUE}#{BOLD}b#{CLEAR}; #{GREEN}end#{CLEAR}; #{RED}'#{CLEAR}#{RED}c#{CLEAR}#{RED}'#{CLEAR} + #{RED}\"#{CLEAR}#{RED}\#{#{CLEAR} #{YELLOW}:#{CLEAR}#{YELLOW}d#{CLEAR} #{RED}}#{CLEAR}#{RED}\"#{CLEAR} #{YELLOW}}#{CLEAR}#{YELLOW}e#{CLEAR}#{YELLOW}\"#{CLEAR}",
-        "__FILE__" => "#{CYAN}#{BOLD}__FILE__#{CLEAR}",
+        "[__FILE__, __LINE__]" => "[#{CYAN}#{BOLD}__FILE__#{CLEAR}, #{CYAN}#{BOLD}__LINE__#{CLEAR}]",
         ":self" => "#{YELLOW}:#{CLEAR}#{YELLOW}self#{CLEAR}",
         ":class" => "#{YELLOW}:#{CLEAR}#{YELLOW}class#{CLEAR}",
         "[:>, 3]" => "[#{YELLOW}:#{CLEAR}#{YELLOW}>#{CLEAR}, #{BLUE}#{BOLD}3#{CLEAR}]",
@@ -58,6 +58,9 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L58
         "foo %w[bar]" => "foo #{RED}%w[#{CLEAR}#{RED}bar#{CLEAR}#{RED}]#{CLEAR}",
         "foo %i[bar]" => "foo #{RED}%i[#{CLEAR}#{RED}bar#{CLEAR}#{RED}]#{CLEAR}",
         "foo :@bar, baz" => "foo #{YELLOW}:#{CLEAR}#{YELLOW}@bar#{CLEAR}, baz",
+        "`echo`" => "#{RED}`#{CLEAR}#{RED}echo#{CLEAR}#{RED}`#{CLEAR}",
+        "\t" => "\t", # not ^I
+        "foo(*%W(bar))" => "foo(*#{RED}%W(#{CLEAR}#{RED}bar#{CLEAR}#{RED})#{CLEAR})",
       }.each do |code, result|
         actual = with_term { IRB::Color.colorize_code(code) }
         assert_equal(result, actual, "Case: colorize_code(#{code.dump})\nResult: #{humanized_literal(actual)}")
-- 
cgit v0.10.2


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

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