@ send-text: Fix reading from stdin when RC is over a socket

This commit is contained in:
Kovid Goyal 2021-10-31 13:55:11 +05:30
parent 4ff3d6a645
commit 6310517ff2
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -67,22 +67,17 @@ def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: Arg
def pipe() -> CmdGenerator:
if sys.stdin.isatty():
ret['exclude_active'] = True
import select
fd = sys.stdin.fileno()
keep_going = True
while keep_going:
rd = select.select([fd], [], [])[0]
if not rd:
break
data = os.read(fd, limit)
if not data:
break # eof
decoded_data = data.decode('utf-8')
if '\x04' in decoded_data:
decoded_data = decoded_data[:decoded_data.index('\x04')]
keep_going = False
ret['data'] = 'text:' + decoded_data
yield ret
from kitty.utils import TTYIO
with TTYIO() as tty:
while keep_going:
data = os.read(tty.tty_fd, limit)
decoded_data = data.decode('utf-8')
if '\x04' in decoded_data:
decoded_data = decoded_data[:decoded_data.index('\x04')]
keep_going = False
ret['data'] = 'text:' + decoded_data
yield ret
else:
while True:
data = sys.stdin.buffer.read(limit)