-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolor.py
76 lines (58 loc) · 2.11 KB
/
color.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -----------------colorama模块的一些常量---------------------------
# Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
# Back: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
# Style: DIM, NORMAL, BRIGHT, RESET_ALL
#
from colorama import init, Fore, Back, Style
init(autoreset=True)
class Colored(object):
# 前景色:红色 背景色:默认
@staticmethod
def red(s):
return Fore.RED + s + Fore.RESET
# 前景色:绿色 背景色:默认
@staticmethod
def green(s):
return Fore.GREEN + s + Fore.RESET
# 前景色:黄色 背景色:默认
def yellow(self, s):
return Fore.YELLOW + s + Fore.RESET
# 前景色:蓝色 背景色:默认
@staticmethod
def blue(s):
return Fore.BLUE + s + Fore.RESET
# 前景色:洋红色 背景色:默认
def magenta(self, s):
return Fore.MAGENTA + s + Fore.RESET
# 前景色:青色 背景色:默认
def cyan(self, s):
return Fore.CYAN + s + Fore.RESET
# 前景色:白色 背景色:默认
def white(self, s):
return Fore.WHITE + s + Fore.RESET
# 前景色:黑色 背景色:默认
def black(self, s):
return Fore.BLACK
# 前景色:白色 背景色:绿色
def white_green(self, s):
return Fore.WHITE + Back.GREEN + s + Fore.RESET + Back.RESET
# 前景色:黑色 背景色:绿色
@staticmethod
def black_green(s):
return Fore.BLACK + Back.GREEN + s + Fore.RESET + Back.RESET
# 前景色:黑色 背景色:红色
@staticmethod
def black_red(s):
return Fore.BLACK + Back.RED + s + Fore.RESET + Back.RESET
if __name__ == '__main__':
color = Colored()
print(color.red('I am red!'))
print(color.green('I am gree!'))
print(color.yellow('I am yellow!'))
print(color.blue('I am blue!'))
print(color.magenta('I am magenta!'))
print(color.cyan('I am cyan!'))
print(color.white('I am white!'))
print(color.white_green('I am white green!'))
print(color.black_green('I am black green!'))
print(color.black_red('I am black RED!'))