1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/reline] 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.

https://github.com/ruby/reline/commit/4a8cca331f
This commit is contained in:
Yusuke Endoh 2019-12-14 15:46:42 +09:00 committed by aycabta
parent 7fd6077d98
commit ec1de789a9

View file

@ -60,14 +60,18 @@ class Reline::ANSI
def self.cursor_pos
begin
res = ''
m = nil
@@input.raw do |stdin|
@@output << "\e[6n"
@@output.flush
while (c = stdin.getc) != 'R'
res << c if c
end
m = res.match(/\e\[(?<row>\d+);(?<column>\d+)/)
(m.pre_match + m.post_match).chars.reverse_each do |ch|
stdin.ungetc ch
end
end
m = res.match(/(?<row>\d+);(?<column>\d+)/)
column = m[:column].to_i - 1
row = m[:row].to_i - 1
rescue Errno::ENOTTY