Skip to content

Commit e1d9240

Browse files
committed
Terminate correctly in the middle of lines higher than the screen
1 parent fe75944 commit e1d9240

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

lib/reline/line_editor.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,12 @@ def rerender
394394
Reline::IOGate.move_cursor_column(0)
395395
@scroll_partial_screen = nil
396396
prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, prompt)
397-
modify_lines(whole_lines).each_with_index do |line, index|
397+
if @previous_line_index
398+
new_lines = whole_lines(index: @previous_line_index, line: @line)
399+
else
400+
new_lines = whole_lines
401+
end
402+
modify_lines(new_lines).each_with_index do |line, index|
398403
@output.write "#{prompt_list ? prompt_list[index] : prompt}#{line}\n"
399404
Reline::IOGate.erase_after_cursor
400405
end
@@ -426,8 +431,13 @@ def rerender
426431
if @is_multiline
427432
if finished?
428433
# Always rerender on finish because output_modifier_proc may return a different output.
429-
line = modify_lines(whole_lines)[@line_index]
430-
prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, prompt)
434+
if @previous_line_index
435+
new_lines = whole_lines(index: @previous_line_index, line: @line)
436+
else
437+
new_lines = whole_lines
438+
end
439+
line = modify_lines(new_lines)[@line_index]
440+
prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines, prompt)
431441
render_partial(prompt, prompt_width, line, @first_line_started_from)
432442
move_cursor_down(@highest_in_all - (@first_line_started_from + @highest_in_this - 1) - 1)
433443
scroll_down(1)
@@ -1324,7 +1334,11 @@ def whole_buffer
13241334
if @buffer_of_lines.size == 1 and @line.nil?
13251335
nil
13261336
else
1327-
whole_lines.join("\n")
1337+
if @previous_line_index
1338+
whole_lines(index: @previous_line_index, line: @line).join("\n")
1339+
else
1340+
whole_lines.join("\n")
1341+
end
13281342
end
13291343
end
13301344

test/reline/yamatanooroti/test_rendering.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,20 @@ def test_autowrap_in_the_middle_of_a_line
692692
EOC
693693
end
694694

695+
def test_terminate_in_the_middle_of_lines
696+
start_terminal(5, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
697+
write("def hoge\n 1\n 2\n 3\n 4\nend\n")
698+
write("\C-p\C-p\C-p\C-e\n")
699+
close
700+
assert_screen(<<~EOC)
701+
prompt> 3
702+
prompt> 4
703+
prompt> end
704+
=> :hoge
705+
prompt>
706+
EOC
707+
end
708+
695709
private def write_inputrc(content)
696710
File.open(@inputrc_file, 'w') do |f|
697711
f.write content

0 commit comments

Comments
 (0)