secretproject/test.py

26 lines
555 B
Python
Raw Permalink Normal View History

2024-07-03 16:12:05 +02:00
from os import get_terminal_size, O_NONBLOCK
from sys import stdin
from termios import tcgetattr, tcsetattr, TCSADRAIN
from tty import setcbreak
def wrapper(f: callable, *args: any):
try:
fd = stdin.fileno()
old_tc = tcgetattr(fd)
setcbreak(fd)
f(*args)
except KeyboardInterrupt:
cprint('2J')
move(0, 0)
finally:
tcsetattr(fd, TCSADRAIN, old_tc)
def main():
while True:
key = stdin.read(1)
print(key.encode())
if __name__ == "__main__":
wrapper(main)