26 lines
No EOL
555 B
Python
26 lines
No EOL
555 B
Python
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) |