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

ruby-changes:69835

From: ima1zumi <ko1@a...>
Date: Sun, 21 Nov 2021 13:56:40 +0900 (JST)
Subject: [ruby-changes:69835] f5829e2935 (master): [ruby/reline] Correct padding space calculation

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

From f5829e293583aa6ba6a1f1314ee22881d58a5f96 Mon Sep 17 00:00:00 2001
From: ima1zumi <mariimaizumi5@g...>
Date: Wed, 17 Nov 2021 00:58:43 +0900
Subject: [ruby/reline] Correct padding space calculation

fix https://github.com/ruby/irb/issues/308

This bug occurred when `dialog.width - calculate_width(s, true)` was negative.

When `dialog.width` is shorter than `old_dialog.width`, it calculates how much padding it has to do. However, there are cases where `s` is longer than `dialog.width`, as in the issue. In that case, `padding_space_with_escape_sequences` will crash.

Here, `old_dialog.width` is longer than `dialog.width`, so I changed the padding width to `old_dialog.width - dialog.width`.

https://github.com/ruby/reline/commit/c581c31e0f
---
 lib/reline/line_editor.rb                   |  3 ++-
 test/reline/yamatanooroti/multiline_repl    | 22 ++++++++++++++++++++++
 test/reline/yamatanooroti/test_rendering.rb | 15 +++++++++++++++
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index f6facc9da81..50bd22b424a 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -858,7 +858,8 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L858
           s = ' ' * width
         else
           s = Reline::Unicode.take_range(visual_lines[start + i], old_dialog.column + dialog.width, width)
-          s = padding_space_with_escape_sequences(s, dialog.width)
+          rerender_width = old_dialog.width - dialog.width
+          s = padding_space_with_escape_sequences(s, rerender_width)
         end
         Reline::IOGate.move_cursor_column(dialog.column + dialog.width)
         @output.write "\e[0m#{s}\e[0m"
diff --git a/test/reline/yamatanooroti/multiline_repl b/test/reline/yamatanooroti/multiline_repl
index da886b8f06f..1f2a0237243 100755
--- a/test/reline/yamatanooroti/multiline_repl
+++ b/test/reline/yamatanooroti/multiline_repl
@@ -137,6 +137,28 @@ opt.on('--autocomplete-super-long') { https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/multiline_repl#L137
     2000.times.map{ s = "Str_#{c}"; c.succ!; s }.select{ |c| c.start_with?(target) }
   }
 }
+
+opt.on('--autocomplete-width-long') {
+  Reline.autocompletion = true
+  Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
+    %w{
+        remove_instance_variable
+        respond_to?
+        ruby2_keywords
+        rand
+        readline
+        readlines
+        require
+        require_relative
+        raise
+        respond_to_missing?
+        redo
+        rescue
+        retry
+        return
+    }.select{ |c| c.start_with?(target) }
+  }
+}
 opt.parse!(ARGV)
 
 begin
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index e1dde835896..f68b614327b 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -1172,6 +1172,21 @@ begin https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/test_rendering.rb#L1172
       EOC
     end
 
+    def test_autocomplete_old_dialog_width_greater_than_dialog_width
+      start_terminal(40, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete-width-long}, startup_message: 'Multiline REPL.')
+      write("0+ \n12345678901234")
+      write("\C-p")
+      write("r")
+      write("a")
+      close
+      assert_screen(<<~'EOC')
+        Multiline REPL.
+        prompt> 0+ ra
+        prompt> 123rand 901234
+                   raise
+      EOC
+    end
+
     def write_inputrc(content)
       File.open(@inputrc_file, 'w') do |f|
         f.write content
-- 
cgit v1.2.1


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

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