| 1 | # get character from stdin |
| 2 |
|
| 3 | import termios, sys, tty |
| 4 | def getch(): |
| 5 | fd = sys.stdin.fileno() |
| 6 | old_settings = termios.tcgetattr(fd) |
| 7 | try: |
| 8 | tty.setraw(fd) |
| 9 | ch = sys.stdin.read(1) |
| 10 | finally: |
| 11 | termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) |
| 12 | return ch |
| 13 |
|
| 14 |
|
| 15 | # echo output |
| 16 |
|
| 17 | import subprocess |
| 18 | def output(*array): |
| 19 | s = "".join(array) |
| 20 | a=subprocess.run(["echo", "-e", s]); |
| 21 |
|
| 22 |
|
| 23 | # ANSI codes for output |
| 24 |
|
| 25 | RESET = "\e[0m" |
| 26 | BOLD = "\e[1m" |
| 27 | UNDERLINED = "\e[4m" |
| 28 | CONTRAST = "\e[7m" |
| 29 |
|
| 30 | TEXT_RED = "\e[91m" |
| 31 | TEXT_GREEN = "\e[92m" |
| 32 | TEXT_YELLOW = "\e[93m" |
| 33 | TEXT_MAGENTA = "\e[95m" |
| 34 | TEXT_CYAN = "\e[96m" |
| 35 |
|
| 36 | BACK_RED = "\e[101m" |
| 37 | BACK_GREEN = "\e[102m" |
| 38 | BACK_YELLOW = "\e[103m" |
| 39 | BACK_MAGENTA = "\e[105m" |
| 40 | BACK_CYAN = "\e[106m" |
| 41 |
|