-
Notifications
You must be signed in to change notification settings - Fork 0
/
printer.py
60 lines (36 loc) · 1.09 KB
/
printer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from threading import Lock
from logger import get_logger
logger = get_logger()
#######################################################
# Printing with Threading
#######################################################
print_lock = Lock()
_print = print # save original
def print(*args, **kwargs):
"""Prevents concurrent printing."""
with print_lock:
_print(*args, **kwargs)
#######################################################
def custom_pretty_print(d):
for key, value in d.items():
text = f"{key}: {value}"
print(text)
logger.info(text)
print()
def coloured(r, g, b, text):
return f"\033[38;2;{r};{g};{b}m{text}\033[0m"
def coloured_print(r, g, b, text):
print(coloured(r, g, b, text))
logger.info(text)
def red(text):
coloured_print(255, 0, 0, text)
def green(text):
coloured_print(0, 255, 0, text)
def blue(text):
coloured_print(0, 0, 255, text)
def yellow(text):
coloured_print(255, 255, 0, text)
def magenta(text):
coloured_print(255, 0, 255, text)
def cyan(text):
coloured_print(0, 255, 255, text)