diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2019-12-14 15:46:42 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2019-12-22 01:57:35 +0900 |
commit | ec1de789a98923417cf983cb3cdaed003c0f8be6 (patch) | |
tree | 80d55c9b385c3743b7b4566483f3b658ab98347b /lib | |
parent | 7fd6077d9896cc10244fb9416ef87ae461c079db (diff) | |
download | ruby-ec1de789a98923417cf983cb3cdaed003c0f8be6.tar.gz |
[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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/reline/ansi.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb index 21c05403ab..376439dc74 100644 --- a/lib/reline/ansi.rb +++ b/lib/reline/ansi.rb @@ -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 |