Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/reline/io/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def inner_getc(timeout_second)
Reline.core.line_editor.handle_signal
end
c = @input.getbyte

# When "Escape non-ASCII Input with Control-V" is enabled in macOS Terminal.app,
# all non-ascii bytes are automatically escaped with `C-v`.
# "\xE3\x81\x82" (U+3042) becomes "\x16\xE3\x16\x81\x16\x82".
(c == 0x16 && @input.tty? && @input.raw(min: 0, time: 0, &:getbyte)) || c
rescue Errno::EIO
# Maybe the I/O has been closed.
Expand Down
29 changes: 29 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def teardown
ENV.delete('RELINE_TEST_PROMPT') if ENV['RELINE_TEST_PROMPT']
end

# Yamatanooroti::TestCase#write converts 0x80-0xff bytes to "\e"+(byte&0x7f).chr
# This method avoids the conversion and writes the string as is.
def write_without_meta_conversion(str)
sync
@pty_input.write(str)
try_sync
end

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, I think changing yamatanooroti's write to not do this conversion is better.
But if we do that, there will be no way to input meta key to yamatanooroti-windows and yamatanooroti-vterm in a common way.


def test_history_back
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write(":a\n")
Expand Down Expand Up @@ -561,6 +569,27 @@ def test_bracketed_paste
close
end

def test_ctrl_v_escaped_input
omit if Reline.core.io_gate.win?

start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')

# When a configuration "Escape non-ASCII Input with Control-V" is enabled
# in macOS Termina.app, all non-ascii characters are escaped with ^V.
write_without_meta_conversion "\C-v\xE3\C-v\x81\C-v\x82"
assert_screen(/prompt> あ/)

# Bracketed pasted content is also escaped
write_without_meta_conversion "\e[200~\C-a\C-v\xE3\C-v\x81\C-v\x84\C-b\e[201~"
assert_screen(/prompt> あ\^Aい\^B/)

# Invalid bytes should be ignored with timeout
write_without_meta_conversion "\C-v\x82\C-v\xA4"
sleep 1
write 'C'
assert_screen(/prompt> あ\^Aい\^BC/)
end

def test_bracketed_paste_with_undo_redo
omit if Reline.core.io_gate.win?
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
Expand Down