[ruby/reline] Fix audoindent including "\v", escape "\v" for

rendering
(https://github.com/ruby/reline/pull/648)

https://github.com/ruby/reline/commit/9c51c577ca
This commit is contained in:
tomoya ishida 2024-04-04 00:36:17 +09:00 committed by Hiroshi SHIBATA
parent 6d82be499b
commit 80e31663f3
No known key found for this signature in database
GPG Key ID: F9CF13417264FAC2
2 changed files with 19 additions and 4 deletions

View File

@ -794,7 +794,7 @@ class Reline::LineEditor
if after = @output_modifier_proc&.call("#{before.join("\n")}\n", complete: complete)
after.lines("\n").map { |l| l.chomp('') }
else
before
before.map { |l| Reline::Unicode.escape_for_print(l) }
end
end
@ -1221,10 +1221,11 @@ class Reline::LineEditor
new_indent = @auto_indent_proc.(@buffer_of_lines.take(line_index + 1).push(''), line_index, byte_pointer, add_newline)
return unless new_indent
@buffer_of_lines[line_index] = ' ' * new_indent + line.lstrip
new_line = ' ' * new_indent + line.lstrip
@buffer_of_lines[line_index] = new_line
if @line_index == line_index
old_indent = line[/\A */].size
@byte_pointer = [@byte_pointer + new_indent - old_indent, 0].max
indent_diff = new_line.bytesize - line.bytesize
@byte_pointer = [@byte_pointer + indent_diff, 0].max
end
end

View File

@ -831,6 +831,20 @@ begin
EOC
end
def test_auto_indent_with_various_spaces
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --auto-indent}, startup_message: 'Multiline REPL.')
write "(\n\C-v"
write "\C-k\n\C-v"
write "\C-k)"
close
assert_screen(<<~EOC)
Multiline REPL.
prompt> (
prompt> ^K
prompt> )
EOC
end
def test_autowrap_in_the_middle_of_a_line
start_terminal(5, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("def abcdefg; end\C-b\C-b\C-b\C-b\C-b")