ruby-changes:65173
From: aycabta <ko1@a...>
Date: Sun, 7 Feb 2021 05:16:59 +0900 (JST)
Subject: [ruby-changes:65173] 300084a854 (master): [ruby/reline] Terminate correctly in the middle of lines higher than the screen
https://git.ruby-lang.org/ruby.git/commit/?id=300084a854 From 300084a85475988ba7c22e335230f31ec415dfc5 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Fri, 5 Feb 2021 21:39:29 +0900 Subject: [ruby/reline] Terminate correctly in the middle of lines higher than the screen https://github.com/ruby/reline/commit/e1d9240ada --- lib/reline/line_editor.rb | 22 ++++++++++++++++++---- test/reline/yamatanooroti/test_rendering.rb | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 31640fd..557b5aa 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -394,7 +394,12 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L394 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 https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L431 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 https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1334 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 diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 22c9316..0ccc331 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -692,6 +692,20 @@ begin https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/test_rendering.rb#L692 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 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/