Debian Codegraph @

js/src/tests/lib/terminal_unix.py

raw
1 import sys
2
3
4 class Terminal:
5 COLOR = {"red": "31", "green": "32", "blue": "34", "gray": "37"}
6 NORMAL_INTENSITY = "1"
7 BRIGHT_INTENSITY = "2"
8 ESCAPE = "\x1b["
9 RESET = "0"
10 SEPARATOR = ";"
11 COLOR_CODE = "m"
12 CLEAR_RIGHT_CODE = "K"
13
14 @classmethod
15 def set_color(cls, color):
16 """
17 color: str - color definition string
18 """
19 mod = Terminal.NORMAL_INTENSITY
20 if color.startswith("bright"):
21 mod = Terminal.BRIGHT_INTENSITY
22 color = color[len("bright") :]
23 color_code = Terminal.COLOR[color]
24
25 sys.stdout.write(cls.ESCAPE + color_code + cls.SEPARATOR + mod + cls.COLOR_CODE)
26
27 @classmethod
28 def reset_color(cls):
29 sys.stdout.write(cls.ESCAPE + cls.RESET + cls.COLOR_CODE)
30
31 @classmethod
32 def clear_right(cls):
33 sys.stdout.write(cls.ESCAPE + cls.CLEAR_RIGHT_CODE)