From 6310517ff231ed79f0d6826f40d3973575eec414 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 31 Oct 2021 13:55:11 +0530 Subject: [PATCH] @ send-text: Fix reading from stdin when RC is over a socket --- kitty/rc/send_text.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/kitty/rc/send_text.py b/kitty/rc/send_text.py index 97ca52440..1a583cb7b 100644 --- a/kitty/rc/send_text.py +++ b/kitty/rc/send_text.py @@ -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)