diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 0d990c2c0a..b95649d0e7 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1131,23 +1131,17 @@ def just_move_cursor if Reline::Unicode::CSI_REGEXP.match?(prompt + line_to_render) @output.write "\e[0m" # clear character decorations end - visual_lines.each_with_index do |line, index| + visual_lines.each do |line| Reline::IOGate.move_cursor_column(0) if line.nil? - if calculate_width(visual_lines[index - 1], true) == Reline::IOGate.get_screen_size.last - # reaches the end of line - if Reline::IOGate.win? and Reline::IOGate.win_legacy_console? - # A newline is automatically inserted if a character is rendered at - # eol on command prompt. - else - # When the cursor is at the end of the line and erases characters - # after the cursor, some terminals delete the character at the - # cursor position. - move_cursor_down(1) - Reline::IOGate.move_cursor_column(0) - end + # reaches the end of line + if Reline::IOGate.win? and Reline::IOGate.win_legacy_console? + # A newline is automatically inserted if a character is rendered at + # eol on command prompt. else - Reline::IOGate.erase_after_cursor + # When the cursor is at the end of the line and erases characters + # after the cursor, some terminals delete the character at the + # cursor position. move_cursor_down(1) Reline::IOGate.move_cursor_column(0) end diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 8ac0c0c096..8dc45353ad 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -85,6 +85,21 @@ def test_two_fullwidth EOC end + def test_fullwidth_autowrap + start_terminal(10, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.') + fullwidth_numbers = '0123456789' + write("'#{fullwidth_numbers * 2}-#{fullwidth_numbers * 2}") + close + assert_screen(<<~EOC) + Multiline REPL. + prompt> '01234 + 5678901234 + 56789-0123 + 4567890123 + 456789 + EOC + end + def test_finish_autowrapped_line start_terminal(10, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.') write("[{'user'=>{'email'=>'a@a', 'id'=>'ABC'}, 'version'=>4, 'status'=>'succeeded'}]\n")