| 1 | import sys |
| 2 | import termios |
| 3 | import tty |
| 4 | |
| 5 | |
| 6 | def getch() -> str: |
| 7 | fd = sys.stdin.fileno() |
| 8 | old_settings = termios.tcgetattr(fd) # type: ignore |
| 9 | try: |
| 10 | tty.setraw(sys.stdin.fileno()) # type: ignore |
| 11 | ch = sys.stdin.read(1) |
| 12 | finally: |
| 13 | termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) # type: ignore |
| 14 | |
| 15 | return ch |