ruby-changes:62901
From: aycabta <ko1@a...>
Date: Sat, 12 Sep 2020 08:38:53 +0900 (JST)
Subject: [ruby-changes:62901] f36dc2b6de (master): [ruby/reline] Treat prompt correctly when Reline.prompt_proc isn't set
https://git.ruby-lang.org/ruby.git/commit/?id=f36dc2b6de From f36dc2b6de54ec6b82766d2134a782d12628a2b9 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Sat, 12 Sep 2020 01:51:26 +0900 Subject: [ruby/reline] Treat prompt correctly when Reline.prompt_proc isn't set https://github.com/ruby/reline/commit/9c9ba0eff3 diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index edea2fa..9bdccae 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -133,7 +133,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L133 if @line_index.zero? 0 else - calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list) + calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list || prompt) end if @prompt_proc prompt = prompt_list[@line_index] @@ -207,10 +207,10 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L207 @is_multiline = false end - private def calculate_height_by_lines(lines, prompt_list) + private def calculate_height_by_lines(lines, prompt) result = 0 + prompt_list = prompt.is_a?(Array) ? prompt : nil lines.each_with_index { |line, i| - prompt = '' prompt = prompt_list[i] if prompt_list and prompt_list[i] result += calculate_height_by_width(calculate_width(prompt, true) + calculate_width(line)) } @@ -343,7 +343,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L343 new_lines = whole_lines end prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines, prompt) - all_height = calculate_height_by_lines(new_lines, prompt_list) + all_height = calculate_height_by_lines(new_lines, prompt_list || prompt) diff = all_height - @highest_in_all move_cursor_down(@highest_in_all - @first_line_started_from - @started_from - 1) if diff > 0 @@ -383,7 +383,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L383 if @line_index.zero? 0 else - calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list) + calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list || prompt) end if @prompt_proc prompt = prompt_list[@line_index] @@ -442,7 +442,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L442 if @line_index.zero? 0 else - calculate_height_by_lines(new_buffer[0..(@line_index - 1)], prompt_list) + calculate_height_by_lines(new_buffer[0..(@line_index - 1)], prompt_list || prompt) end @started_from = calculate_height_by_width(prompt_width + @cursor) - 1 move_cursor_down(@first_line_started_from + @started_from) diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index effeb7c..0ab43fa 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -100,6 +100,22 @@ begin https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/test_rendering.rb#L100 EOC end + def test_finish_autowrapped_line_in_the_middle_of_multilines + start_terminal(30, 16, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}) + sleep 0.5 + write("<<~EOM\n ABCDEFG\nEOM\n") + close + assert_screen(<<~'EOC') + Multiline REPL. + prompt> <<~EOM + prompt> ABCDEF + G + prompt> EOM + => "ABCDEFG\n" + prompt> + EOC + end + def test_prompt File.open(@inputrc_file, 'w') do |f| f.write <<~'LINES' -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/