Skip to content

Commit 4a8cca3

Browse files
committed
Preserve the input buffer across cursor_pos
The old version of cursor_pos discards the input buffer, which made IRB ignore the input immediately after IRB is invoked. This change keeps the input before cursor_pos by using ungetc.
1 parent 7828423 commit 4a8cca3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/reline/ansi.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,18 @@ def self.set_screen_size(rows, columns)
6060
def self.cursor_pos
6161
begin
6262
res = ''
63+
m = nil
6364
@@input.raw do |stdin|
6465
@@output << "\e[6n"
6566
@@output.flush
6667
while (c = stdin.getc) != 'R'
6768
res << c if c
6869
end
70+
m = res.match(/\e\[(?<row>\d+);(?<column>\d+)/)
71+
(m.pre_match + m.post_match).chars.reverse_each do |ch|
72+
stdin.ungetc ch
73+
end
6974
end
70-
m = res.match(/(?<row>\d+);(?<column>\d+)/)
7175
column = m[:column].to_i - 1
7276
row = m[:row].to_i - 1
7377
rescue Errno::ENOTTY

0 commit comments

Comments
 (0)