Skip to content

Commit 0d66c33

Browse files
authored
Input with eof and no newline bugfix (#671)
1 parent 29714df commit 0d66c33

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

lib/reline/ansi.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def self.cursor_pos
284284
buf = @@output.pread(@@output.pos, 0)
285285
row = buf.count("\n")
286286
column = buf.rindex("\n") ? (buf.size - buf.rindex("\n")) - 1 : 0
287-
rescue Errno::ESPIPE
287+
rescue Errno::ESPIPE, IOError
288288
# Just returns column 1 for ambiguous width because this I/O is not
289289
# tty and can't seek.
290290
row = 0

lib/reline/line_editor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ def input_key(key)
11181118
end
11191119
end
11201120
if key.char.nil?
1121+
process_insert(force: true)
11211122
if @first_char
11221123
@eof = true
11231124
end

test/reline/yamatanooroti/test_rendering.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,18 +945,30 @@ def test_force_enter
945945
EOC
946946
end
947947

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

960+
def test_eof_without_newline
961+
omit if Reline.core.io_gate.win?
962+
cmd = %Q{ruby -e 'print(%{hello})' | ruby -I#{@pwd}/lib -rreline -e 'p Reline.readline(%{> })'}
963+
start_terminal(40, 50, ['bash', '-c', cmd])
964+
sleep 1
965+
close rescue nil
966+
assert_screen(<<~'EOC')
967+
> hello
968+
"hello"
969+
EOC
970+
end
971+
960972
def test_em_set_mark_and_em_exchange_mark
961973
start_terminal(10, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
962974
write("aaa bbb ccc ddd\M-b\M-b\M-\x20\M-b\C-x\C-xX\C-x\C-xY")

0 commit comments

Comments
 (0)