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

ruby-changes:70414

From: aycabta <ko1@a...>
Date: Tue, 21 Dec 2021 15:50:45 +0900 (JST)
Subject: [ruby-changes:70414] 1855f901c8 (master): [ruby/irb] Check colorize option correctly to clear char attr and don't use it for tests

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

From 1855f901c801a4c21e0d2834da8ef914bf47f3d9 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Tue, 21 Dec 2021 15:50:59 +0900
Subject: [ruby/irb] Check colorize option correctly to clear char attr and
 don't use it for tests

https://github.com/ruby/irb/commit/de561cafeb
---
 lib/irb.rb               | 9 ++++++---
 test/irb/test_context.rb | 6 +++++-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/irb.rb b/lib/irb.rb
index f48a0a2d4df..6887d5596ec 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -824,17 +824,20 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L824
           diff_size = output_width - Reline::Unicode.calculate_width(first_line, true)
           if diff_size.positive? and output_width > winwidth
             lines, _ = Reline::Unicode.split_by_width(first_line, winwidth - diff_size - 3)
-            str = "%s...\e[0m" % lines.first
+            str = "%s..." % lines.first
+            str += "\e[0m" if @context.use_colorize
             multiline_p = false
           else
-            str = str.gsub(/(\A.*?\n).*/m, "\\1...\e[0m")
+            str = str.gsub(/(\A.*?\n).*/m, "\\1...")
+            str += "\e[0m" if @context.use_colorize
           end
         else
           output_width = Reline::Unicode.calculate_width(@context.return_format % str, true)
           diff_size = output_width - Reline::Unicode.calculate_width(str, true)
           if diff_size.positive? and output_width > winwidth
             lines, _ = Reline::Unicode.split_by_width(str, winwidth - diff_size - 3)
-            str = "%s...\e[0m" % lines.first
+            str = "%s..." % lines.first
+            str += "\e[0m" if @context.use_colorize
           end
         end
       end
diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb
index d908195e6a5..42f82fc37ed 100644
--- a/test/irb/test_context.rb
+++ b/test/irb/test_context.rb
@@ -259,6 +259,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_context.rb#L259
     end
 
     def test_omit_on_assignment
+      IRB.conf[:USE_COLORIZE] = false
       input = TestInputMethod.new([
         "a = [1] * 100\n",
         "a\n",
@@ -322,6 +323,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_context.rb#L323
     end
 
     def test_omit_multiline_on_assignment
+      IRB.conf[:USE_COLORIZE] = false
       input = TestInputMethod.new([
         "class A; def inspect; ([?* * 1000] * 3).join(%{\\n}); end; end; a = A.new\n",
         "a\n"
@@ -347,7 +349,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_context.rb#L349
         irb.eval_input
       end
       assert_empty err
-      assert_equal("=> #{value_first_line[0..(input.winsize.last - 9)]}...\e[0m\n=> \n#{value}\n", out)
+      assert_equal("=> #{value_first_line[0..(input.winsize.last - 9)]}...\n=> \n#{value}\n", out)
       irb.context.evaluate('A.remove_method(:inspect)', 0)
 
       input.reset
@@ -395,6 +397,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_context.rb#L397
       # Default
       IRB.conf[:ECHO] = nil
       IRB.conf[:ECHO_ON_ASSIGNMENT] = nil
+      IRB.conf[:USE_COLORIZE] = false
       input = TestInputMethod.new()
       irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
 
@@ -422,6 +425,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_context.rb#L425
       def main.inspect
         "abc\ndef"
       end
+      IRB.conf[:USE_COLORIZE] = false
       input = TestInputMethod.new([
         "self"
       ])
-- 
cgit v1.2.1


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

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