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\[(?\d+);(?\d+)/) + (m.pre_match + m.post_match).chars.reverse_each do |ch| + stdin.ungetc ch + end end - m = res.match(/(?\d+);(?\d+)/) column = m[:column].to_i - 1 row = m[:row].to_i - 1 rescue Errno::ENOTTY