Simplify garbage clear logic

This commit is contained in:
Kovid Goyal 2022-03-15 11:41:59 +05:30
parent bdb55a02fa
commit 9e317971b4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -519,14 +519,13 @@ def drain_potential_tty_garbage(p: 'subprocess.Popen[bytes]', data_request: str)
termios.tcflush(tty.fileno(), termios.TCIFLUSH)
data = b''
start = time.monotonic()
with open(tty.fileno(), 'rb', closefd=False) as tf:
os.set_blocking(tf.fileno(), False)
from tty import setraw
setraw(tf.fileno(), termios.TCSANOW)
while time.monotonic() - start < 1 and select([tf], [], [], 0.075)[0]:
data += tf.read()
if b'KITTY_DATA_END' in data:
return
while time.monotonic() - start < 1 and select([tty], [], [], 0.075)[0]:
q = os.read(tty.fileno(), io.DEFAULT_BUFFER_SIZE)
if not q:
break
data += q
if b'KITTY_DATA_END' in data:
return
def run_ssh(ssh_args: List[str], server_args: List[str], found_extra_args: Tuple[str, ...]) -> NoReturn: