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:
parent
7fd6077d98
commit
ec1de789a9
1 changed files with 5 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue