summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-01-05 18:29:09 +0900
committeraycabta <aycabta@gmail.com>2021-01-08 13:25:18 +0900
commit76c9a3c8c633241c86024a027a644f1dd6dbbc44 (patch)
tree52328c4d8b67d028645db7b17846a9e1a097aabe
parent88af5085dbf61dcd815e66aa9fe96c7d612c9747 (diff)
[ruby/reline] Suppress crashing when dynamic_prompt_proc returns a broken prompt list
Co-authored-by: Juanito Fatas <me@juanitofatas.com> https://github.com/ruby/reline/commit/558f7be168
-rw-r--r--lib/reline/line_editor.rb7
-rw-r--r--test/reline/yamatanooroti/test_rendering.rb12
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index bf2732823b..65004cad18 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -112,6 +112,7 @@ class Reline::LineEditor
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
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 ce8c4cec24..9c8df1f215 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -450,6 +450,18 @@ begin
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