Skip to content

Commit

Permalink
Some I/O in test doesn't have "position"
Browse files Browse the repository at this point in the history
Just returns column 1 for ambiguous width because this I/O is not tty and can't
seek.
  • Loading branch information
aycabta committed May 11, 2020
1 parent d39be24 commit 7a7854d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/reline/ansi.rb
Expand Up @@ -116,9 +116,16 @@ def self.cursor_pos
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
Expand Down

0 comments on commit 7a7854d

Please sign in to comment.