-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathColored-print.py
76 lines (62 loc) · 2.24 KB
/
Colored-print.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
#Author:D4Vinci
#print with colors in any platform with colorama and if it not working because u on windows then use method 2 to print with powershell ;)
#Console Colors
G = '\033[92m' #green
Y = '\033[93m' #yellow
B = '\033[94m' #blue
R = '\033[91m' #red
W = '\033[0m' #white
def colored_print(text,color):
#Check if we are running this on windows platform
is_windows = sys.platform.startswith('win')
if is_windows:
try:
import colorama
method = 1
except:
method = 2
if method == 1:
from colorama import init, AnsiToWin32
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream
print >>stream, color + text
elif method == 2:
if color == '\033[92m':
color = "G"
if color == '\033[93m':
color = "Y"
if color == '\033[94m':
color = "B"
if color == '\033[91m':
color = "R"
if color == '\033[0m':
color = "W"
def powershell_print(text,color):
color = color.upper()
powershell_colors = {"B":"Blue","G":"Green","R":"Red","W":"White","Y":"Yellow"}
import subprocess,sys
subprocess.Popen('powershell -command "write-host {{"{0}"}} -foreground "{1}" " '.format(text,powershell_colors[color]) , stdout=sys.stdout)
powershell_print(text,color)
else:
print color+text+'\033[0m'
#####################################
#### Or you can use this method #####
#####################################
# Check if we are running this on windows platform
is_windows = sys.platform.startswith('win')
# Console Colors
if is_windows:
# Windows deserve coloring too :D
G = '\033[92m' # green
Y = '\033[93m' # yellow
B = '\033[94m' # blue
R = '\033[91m' # red
W = '\033[0m' # white
try:
import win_unicode_console , colorama
win_unicode_console.enable()
colorama.init()
#Now the unicode will work ^_^
except:
print("[!] Error: Coloring libraries not installed ,no coloring will be used [Check the readme]")
G = Y = B = R = W = G = Y = B = R = W = ''