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

ruby-changes:64791

From: aycabta <ko1@a...>
Date: Fri, 8 Jan 2021 13:38:42 +0900 (JST)
Subject: [ruby-changes:64791] 76c9a3c8c6 (master): [ruby/reline] Suppress crashing when dynamic_prompt_proc returns a broken prompt list

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

From 76c9a3c8c633241c86024a027a644f1dd6dbbc44 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Tue, 5 Jan 2021 18:29:09 +0900
Subject: [ruby/reline] Suppress crashing when dynamic_prompt_proc returns a
 broken prompt list

Co-authored-by: Juanito Fatas <me@j...>

https://github.com/ruby/reline/commit/558f7be168

diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index bf27328..65004ca 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -112,6 +112,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L112
           use_cached_prompt_list = true
         end
       end
+      use_cached_prompt_list = false if @rerender_all
       if use_cached_prompt_list
         prompt_list = @cached_prompt_list
       else
@@ -123,6 +124,12 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L124
       prompt_list = prompt_list.map{ |pr| mode_string + pr } if mode_string
       prompt = prompt_list[@line_index]
       prompt = prompt_list[0] if prompt.nil?
+      prompt = prompt_list.last if prompt.nil?
+      if buffer.size > prompt_list.size
+        (buffer.size - prompt_list.size).times do
+          prompt_list << prompt_list.last
+        end
+      end
       prompt_width = calculate_width(prompt, true)
       [prompt, prompt_width, prompt_list]
     else
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index ce8c4ce..9c8df1f 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -450,6 +450,18 @@ begin https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/test_rendering.rb#L450
       EOC
     end
 
+    def test_broken_prompt_list
+      start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl --broken-dynamic-prompt}, startup_message: 'Multiline REPL.')
+      write("def hoge\n  3\nend")
+      close
+      assert_screen(<<~EOC)
+        Multiline REPL.
+        [0000]> def hoge
+        [0001]>   3
+        [0001]> end
+      EOC
+    end
+
     def test_enable_bracketed_paste
       omit if Reline::IOGate.win?
       write_inputrc <<~LINES
-- 
cgit v0.10.2


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

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