-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprt_cmd_color.py
59 lines (45 loc) · 1.38 KB
/
prt_cmd_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
#-*- coding:utf-8 -*-#
#filename: prt_cmd_color.py
import ctypes,sys
STD_INPUT_HANDLE = -10
STD_OUTPUT_HANDLE = -11
STD_ERROR_HANDLE = -12
#×ÖÌåÑÕÉ«¶¨Òå text colors
FOREGROUND_BLUE = 0x09 # blue.
FOREGROUND_GREEN = 0x0a # green.
FOREGROUND_RED = 0x0c # red.
FOREGROUND_YELLOW = 0x0e # yellow.
# ±³¾°ÑÕÉ«¶¨Òå background colors
BACKGROUND_YELLOW = 0xe0 # yellow.
# get handle
std_out_handle = ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
def set_cmd_text_color(color, handle=std_out_handle):
Bool = ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color)
return Bool
#reset white
def resetColor():
set_cmd_text_color(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
#green
def printGreen(mess):
set_cmd_text_color(FOREGROUND_GREEN)
sys.stdout.write(mess + '\n')
resetColor()
#red
def printRed(mess):
set_cmd_text_color(FOREGROUND_RED)
sys.stdout.write(mess + '\n')
resetColor()
#yellow
def printYellow(mess):
set_cmd_text_color(FOREGROUND_YELLOW)
sys.stdout.write(mess + '\n')
resetColor()
#white bkground and black text
def printYellowRed(mess):
set_cmd_text_color(BACKGROUND_YELLOW | FOREGROUND_RED)
sys.stdout.write(mess + '\n')
resetColor()
# if __name__ == '__main__':
# printGreen('printGreen:Gree Color Text')
# printRed('printRed:Red Color Text')
# printYellow('printYellow:Yellow Color Text')