From 7a7854d8c18b0ec15b3c050aff179f9753a44210 Mon Sep 17 00:00:00 2001 From: aycabta Date: Tue, 12 May 2020 00:51:47 +0900 Subject: [PATCH] Some I/O in test doesn't have "position" Just returns column 1 for ambiguous width because this I/O is not tty and can't seek. --- lib/reline/ansi.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb index 3ef02d6e7a..91f4cee3c7 100644 --- a/lib/reline/ansi.rb +++ b/lib/reline/ansi.rb @@ -116,9 +116,16 @@ class Reline::ANSI column = m[:column].to_i - 1 row = m[:row].to_i - 1 rescue Errno::ENOTTY - buf = @@output.pread(@@output.pos, 0) - row = buf.count("\n") - column = buf.rindex("\n") ? (buf.size - buf.rindex("\n")) - 1 : 0 + begin + buf = @@output.pread(@@output.pos, 0) + row = buf.count("\n") + column = buf.rindex("\n") ? (buf.size - buf.rindex("\n")) - 1 : 0 + rescue Errno::ESPIPE + # Just returns column 1 for ambiguous width because this I/O is not + # tty and can't seek. + row = 0 + column = 1 + end end Reline::CursorPos.new(column, row) end