1def colored(r, g, b, text):
2 return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
3
4text = 'Hello, World'
5colored_text = colored(255, 0, 0, text)
6print(colored_text)
7
8#or
9
10print(colored(255, 0, 0, 'Hello, World'))
1from termcolor import colored
2print colored('hello', 'red'), colored('world', 'green')
1class colors:
2 '''Colors class:
3 reset all colors with colors.reset
4 two subclasses fg for foreground and bg for background.
5 use as colors.subclass.colorname.
6 i.e. colors.fg.red or colors.bg.green
7 also, the generic bold, disable, underline, reverse, strikethrough,
8 and invisible work with the main class
9 i.e. colors.bold
10 '''
11 reset='\033[0m'
12 bold='\033[01m'
13 disable='\033[02m'
14 underline='\033[04m'
15 reverse='\033[07m'
16 strikethrough='\033[09m'
17 invisible='\033[08m'
18 class fg:
19 black='\033[30m'
20 red='\033[31m'
21 green='\033[32m'
22 orange='\033[33m'
23 blue='\033[34m'
24 purple='\033[35m'
25 cyan='\033[36m'
26 lightgrey='\033[37m'
27 darkgrey='\033[90m'
28 lightred='\033[91m'
29 lightgreen='\033[92m'
30 yellow='\033[93m'
31 lightblue='\033[94m'
32 pink='\033[95m'
33 lightcyan='\033[96m'
34 class bg:
35 black='\033[40m'
36 red='\033[41m'
37 green='\033[42m'
38 orange='\033[43m'
39 blue='\033[44m'
40 purple='\033[45m'
41 cyan='\033[46m'
42 lightgrey='\033[47m'
43
1CEND = '\33[0m'
2CBOLD = '\33[1m'
3CITALIC = '\33[3m'
4CURL = '\33[4m'
5CBLINK = '\33[5m'
6CBLINK2 = '\33[6m'
7CSELECTED = '\33[7m'
8
9CBLACK = '\33[30m'
10CRED = '\33[31m'
11CGREEN = '\33[32m'
12CYELLOW = '\33[33m'
13CBLUE = '\33[34m'
14CVIOLET = '\33[35m'
15CBEIGE = '\33[36m'
16CWHITE = '\33[37m'
17
18CBLACKBG = '\33[40m'
19CREDBG = '\33[41m'
20CGREENBG = '\33[42m'
21CYELLOWBG = '\33[43m'
22CBLUEBG = '\33[44m'
23CVIOLETBG = '\33[45m'
24CBEIGEBG = '\33[46m'
25CWHITEBG = '\33[47m'
26
27CGREY = '\33[90m'
28CRED2 = '\33[91m'
29CGREEN2 = '\33[92m'
30CYELLOW2 = '\33[93m'
31CBLUE2 = '\33[94m'
32CVIOLET2 = '\33[95m'
33CBEIGE2 = '\33[96m'
34CWHITE2 = '\33[97m'
35
36CGREYBG = '\33[100m'
37CREDBG2 = '\33[101m'
38CGREENBG2 = '\33[102m'
39CYELLOWBG2 = '\33[103m'
40CBLUEBG2 = '\33[104m'
41CVIOLETBG2 = '\33[105m'
42CBEIGEBG2 = '\33[106m'
43CWHITEBG2 = '\33[107m'
44
1class bcolors:
2 HEADER = '\033[95m'
3 OKBLUE = '\033[94m'
4 OKCYAN = '\033[96m'
5 OKGREEN = '\033[92m'
6 WARNING = '\033[93m'
7 FAIL = '\033[91m'
8 ENDC = '\033[0m'
9 BOLD = '\033[1m'
10 UNDERLINE = '\033[4m'
11