From 2e34b35a0ff7c326d1260a7f4dd3e4a9febe3d12 Mon Sep 17 00:00:00 2001 From: aycabta Date: Sat, 5 Sep 2020 21:13:47 +0900 Subject: [PATCH] [ruby/reline] Skip the nil obtained from getc The nil means there is nothing in the buffer in some systems. Incidentally, Errno::EIO is raised if the I/O is closed. https://github.com/ruby/reline/commit/c698634e74 --- lib/reline/ansi.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb index d2c32898b3..8b6b10cb89 100644 --- a/lib/reline/ansi.rb +++ b/lib/reline/ansi.rb @@ -65,7 +65,9 @@ class Reline::ANSI unless @@buf.empty? return @@buf.shift end - c = @@input.raw(intr: true, &:getbyte) + until c = @@input.raw(intr: true, &:getbyte) + sleep 0.1 + end (c == 0x16 && @@input.raw(min: 0, tim: 0, &:getbyte)) || c rescue Errno::EIO # Maybe the I/O has been closed. @@ -112,7 +114,9 @@ class Reline::ANSI @@input.raw do |stdin| @@output << "\e[6n" @@output.flush - while (c = stdin.getc) + loop do + c = stdin.getc + next if c.nil? res << c m = res.match(/\e\[(?\d+);(?\d+)R/) break if m