Skip to content

Commit

Permalink
[ruby/reline] Input with eof and no newline bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng authored and matzbot committed Apr 29, 2024
1 parent 4c41203 commit 814d4b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/reline/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def self.cursor_pos
buf = @@output.pread(@@output.pos, 0)
row = buf.count("\n")
column = buf.rindex("\n") ? (buf.size - buf.rindex("\n")) - 1 : 0
rescue Errno::ESPIPE
rescue Errno::ESPIPE, IOError
# Just returns column 1 for ambiguous width because this I/O is not
# tty and can't seek.
row = 0
Expand Down
1 change: 1 addition & 0 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ def input_key(key)
end
end
if key.char.nil?
process_insert(force: true)
if @first_char
@eof = true
end
Expand Down
16 changes: 14 additions & 2 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -945,18 +945,30 @@ def test_force_enter
EOC
end

def test_with_newline
def test_eof_with_newline
omit if Reline.core.io_gate.win?
cmd = %Q{ruby -e 'print(%Q{abc def \\e\\r})' | ruby -I#{@pwd}/lib -rreline -e 'p Reline.readline(%{> })'}
start_terminal(40, 50, ['bash', '-c', cmd])
sleep 1
close
close rescue nil
assert_screen(<<~'EOC')
> abc def
"abc def "
EOC
end

def test_eof_without_newline
omit if Reline.core.io_gate.win?
cmd = %Q{ruby -e 'print(%{hello})' | ruby -I#{@pwd}/lib -rreline -e 'p Reline.readline(%{> })'}
start_terminal(40, 50, ['bash', '-c', cmd])
sleep 1
close rescue nil
assert_screen(<<~'EOC')
> hello
"hello"
EOC
end

def test_em_set_mark_and_em_exchange_mark
start_terminal(10, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("aaa bbb ccc ddd\M-b\M-b\M-\x20\M-b\C-x\C-xX\C-x\C-xY")
Expand Down

0 comments on commit 814d4b5

Please sign in to comment.