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.
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
|
def self.cursor_pos
|
||||||
begin
|
begin
|
||||||
res = ''
|
res = ''
|
||||||
|
m = nil
|
||||||
@@input.raw do |stdin|
|
@@input.raw do |stdin|
|
||||||
@@output << "\e[6n"
|
@@output << "\e[6n"
|
||||||
@@output.flush
|
@@output.flush
|
||||||
while (c = stdin.getc) != 'R'
|
while (c = stdin.getc) != 'R'
|
||||||
res << c if c
|
res << c if c
|
||||||
end
|
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
|
end
|
||||||
m = res.match(/(?<row>\d+);(?<column>\d+)/)
|
|
||||||
column = m[:column].to_i - 1
|
column = m[:column].to_i - 1
|
||||||
row = m[:row].to_i - 1
|
row = m[:row].to_i - 1
|
||||||
rescue Errno::ENOTTY
|
rescue Errno::ENOTTY
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue