Skip to content

Commit 558f7be

Browse files
aycabtaJuanitoFatas
andcommitted
Suppress crashing when dynamic_prompt_proc returns a broken prompt list
Co-authored-by: Juanito Fatas <me@juanitofatas.com>
1 parent 7c24276 commit 558f7be

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

bin/multiline_repl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ opt.on('--dynamic-prompt') {
2222
}
2323
}
2424
}
25+
opt.on('--broken-dynamic-prompt') {
26+
Reline.prompt_proc = proc { |lines|
27+
range = lines.size > 1 ? (0..(lines.size - 2)) : (0..0)
28+
lines[range].each_with_index.map { |l, i|
29+
'[%04d]> ' % i
30+
}
31+
}
32+
}
2533
opt.on('--auto-indent') {
2634
AutoIndent.new
2735
}

lib/reline/line_editor.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def simplified_rendering?
112112
use_cached_prompt_list = true
113113
end
114114
end
115+
use_cached_prompt_list = false if @rerender_all
115116
if use_cached_prompt_list
116117
prompt_list = @cached_prompt_list
117118
else
@@ -123,6 +124,12 @@ def simplified_rendering?
123124
prompt_list = prompt_list.map{ |pr| mode_string + pr } if mode_string
124125
prompt = prompt_list[@line_index]
125126
prompt = prompt_list[0] if prompt.nil?
127+
prompt = prompt_list.last if prompt.nil?
128+
if buffer.size > prompt_list.size
129+
(buffer.size - prompt_list.size).times do
130+
prompt_list << prompt_list.last
131+
end
132+
end
126133
prompt_width = calculate_width(prompt, true)
127134
[prompt, prompt_width, prompt_list]
128135
else

test/reline/yamatanooroti/test_rendering.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,18 @@ def test_prompt_list_caching
450450
EOC
451451
end
452452

453+
def test_broken_prompt_list
454+
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl --broken-dynamic-prompt}, startup_message: 'Multiline REPL.')
455+
write("def hoge\n 3\nend")
456+
close
457+
assert_screen(<<~EOC)
458+
Multiline REPL.
459+
[0000]> def hoge
460+
[0001]> 3
461+
[0001]> end
462+
EOC
463+
end
464+
453465
def test_enable_bracketed_paste
454466
omit if Reline::IOGate.win?
455467
write_inputrc <<~LINES

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy