[ruby/reline] Terminate correctly in the middle of lines higher than the screen

https://github.com/ruby/reline/commit/e1d9240ada
This commit is contained in:
aycabta 2021-02-05 21:39:29 +09:00
Родитель fee19da230
Коммит 300084a854
2 изменённых файлов: 32 добавлений и 4 удалений

Просмотреть файл

@ -394,7 +394,12 @@ class Reline::LineEditor
Reline::IOGate.move_cursor_column(0)
@scroll_partial_screen = nil
prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, prompt)
modify_lines(whole_lines).each_with_index do |line, index|
if @previous_line_index
new_lines = whole_lines(index: @previous_line_index, line: @line)
else
new_lines = whole_lines
end
modify_lines(new_lines).each_with_index do |line, index|
@output.write "#{prompt_list ? prompt_list[index] : prompt}#{line}\n"
Reline::IOGate.erase_after_cursor
end
@ -426,8 +431,13 @@ class Reline::LineEditor
if @is_multiline
if finished?
# Always rerender on finish because output_modifier_proc may return a different output.
line = modify_lines(whole_lines)[@line_index]
prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, prompt)
if @previous_line_index
new_lines = whole_lines(index: @previous_line_index, line: @line)
else
new_lines = whole_lines
end
line = modify_lines(new_lines)[@line_index]
prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines, prompt)
render_partial(prompt, prompt_width, line, @first_line_started_from)
move_cursor_down(@highest_in_all - (@first_line_started_from + @highest_in_this - 1) - 1)
scroll_down(1)
@ -1324,7 +1334,11 @@ class Reline::LineEditor
if @buffer_of_lines.size == 1 and @line.nil?
nil
else
whole_lines.join("\n")
if @previous_line_index
whole_lines(index: @previous_line_index, line: @line).join("\n")
else
whole_lines.join("\n")
end
end
end

Просмотреть файл

@ -692,6 +692,20 @@ begin
EOC
end
def test_terminate_in_the_middle_of_lines
start_terminal(5, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
write("def hoge\n 1\n 2\n 3\n 4\nend\n")
write("\C-p\C-p\C-p\C-e\n")
close
assert_screen(<<~EOC)
prompt> 3
prompt> 4
prompt> end
=> :hoge
prompt>
EOC
end
private def write_inputrc(content)
File.open(@inputrc_file, 'w') do |f|
f.write content