-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path029.PrintColors.py
34 lines (31 loc) · 1.08 KB
/
029.PrintColors.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
# Some ANSI escape sequences for colours and effects
BLACK = '\u001b[30m'
RED = '\u001b[31m'
GREEN = '\u001b[32m'
YELLOW = '\u001b[33m'
BLUE = '\u001b[34m'
MAGENTA = '\u001b[35m'
CYAN = '\u001b[36m'
WHITE = '\u001b[37m'
RESET = '\u001b[0m'
BOLD = '\u001b[1m'
UNDERLINE = '\u001b[4m'
REVERSE = '\u001b[7m'
#def colour_print(text: str,effect :str) -> None:
def colour_print(text: str,*effects :str) -> None:
effect_string = "".join(effects)
output_string = "{0}{1}{2}".format(effect_string,text,RESET)
print(output_string)
colour_print("Hello, Red", RED)
colour_print("Hello, Red in bold", RED,BOLD)
# test that the colour was reset
print("This should be in the default terminal colour")
colour_print("Hello, Blue", BLUE)
colour_print("Hello, Blue reversed", BLUE,REVERSE)
colour_print("Hello, Blue reversed and underlined", BLUE,REVERSE,UNDERLINE)
colour_print("Hello, Yellow", YELLOW)
colour_print("Hello, Yellow bold", YELLOW,BOLD)
colour_print("Hello, Bold", BOLD)
colour_print("Hello, Underline", UNDERLINE)
colour_print("Hello, Reverse", REVERSE)
colour_print("Hello, Black", BLACK)