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

ruby-changes:73668

From: tompng <ko1@a...>
Date: Thu, 22 Sep 2022 00:37:50 +0900 (JST)
Subject: [ruby-changes:73668] 369f1668cd (master): [ruby/irb] Rewrite on_scan proc to be more readable.

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

From 369f1668cd9dd4f361d9082bb729aa510835126b Mon Sep 17 00:00:00 2001
From: tompng <tomoyapenguin@g...>
Date: Mon, 19 Sep 2022 14:14:10 +0900
Subject: [ruby/irb] Rewrite on_scan proc to be more readable.

https://github.com/ruby/irb/commit/da54e7f081
---
 lib/irb/color.rb | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/irb/color.rb b/lib/irb/color.rb
index 401966d181..7071696cb2 100644
--- a/lib/irb/color.rb
+++ b/lib/irb/color.rb
@@ -176,14 +176,18 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L176
           end
 
           on_scan = proc do |elem|
-            str = elem.tok
             start_pos = line_positions[elem.pos[0] - 1] + elem.pos[1]
-            end_pos = start_pos + str.bytesize
-            next if start_pos < byte_pos
 
-            yield(nil, inner_code.byteslice(byte_pos...start_pos), nil) if byte_pos < start_pos
-            yield(elem.event, str, elem.state)
-            byte_pos = end_pos
+            # yield uncolorable code
+            if byte_pos < start_pos
+              yield(nil, inner_code.byteslice(byte_pos...start_pos), nil)
+            end
+
+            if byte_pos <= start_pos
+              str = elem.tok
+              yield(elem.event, str, elem.state)
+              byte_pos = start_pos + str.bytesize
+            end
           end
 
           if lexer.respond_to?(:scan) # Ruby 2.7+
-- 
cgit v1.2.1


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

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