Framework for testing with external programs via a PTY

This commit is contained in:
Kovid Goyal
2022-02-21 14:08:10 +05:30
parent a559210923
commit 63f974531b
3 changed files with 113 additions and 9 deletions

View File

@@ -9,7 +9,7 @@ import os
import re
import string
import sys
from contextlib import suppress
from contextlib import contextmanager, suppress
from functools import lru_cache
from time import monotonic
from typing import (
@@ -501,6 +501,21 @@ class TTYIO:
break
@contextmanager
def no_echo(fd: int = -1) -> Generator[None, None, None]:
import termios
if fd < 0:
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~termios.ECHO
try:
termios.tcsetattr(fd, termios.TCSADRAIN, new)
yield
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)
def natsort_ints(iterable: Iterable[str]) -> List[str]:
def convert(text: str) -> Union[int, str]: