ruby-changes:59357
From: Yusuke <ko1@a...>
Date: Sun, 22 Dec 2019 01:58:02 +0900 (JST)
Subject: [ruby-changes:59357] ec1de789a9 (master): [ruby/reline] Preserve the input buffer across cursor_pos
https://git.ruby-lang.org/ruby.git/commit/?id=ec1de789a9 From ec1de789a98923417cf983cb3cdaed003c0f8be6 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Sat, 14 Dec 2019 15:46:42 +0900 Subject: [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 diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb index 21c0540..376439d 100644 --- a/lib/reline/ansi.rb +++ b/lib/reline/ansi.rb @@ -60,14 +60,18 @@ class Reline::ANSI https://github.com/ruby/ruby/blob/trunk/lib/reline/ansi.rb#L60 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/