-
Notifications
You must be signed in to change notification settings - Fork 0
/
TxColor.py
40 lines (38 loc) · 1.3 KB
/
TxColor.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
from colorama import init
init()
color_dict1 = {"b" : ["30","40"], #black
"r" : ["31","41"], #red
"g" : ["32","42"],#green
"y" : ["33","43"], #yellow
"B" : ["34","44"], #blue
"p" : ["35","45"], #purple
"c" : ["36","46"], #cyan
"w" : ["37","47"]} #white
code_list = []
tag_list = []
for i in color_dict1.keys():
tag1 = "<" + i + ">"
code1 = "\033[1;" + color_dict1[i][0] + ";40m"
tag_list.append(tag1)
code_list.append(code1)
for r in color_dict1.keys():
tag2 = "<" + i + r + ">"
code2 = '\033[1;' + color_dict1[i][0] + ";" + color_dict1[r][1] + "m"
code_list.append(code2)
tag_list.append(tag2)
color_dict2 = dict(zip(tag_list, code_list))
def find(text):
str1 = text
tag_in_text = str1.count("<")
tag_in_text /= 2
counted_tags = 0
for i in range(int(tag_in_text)):
for r in tag_list:
quantity_similar_tags = str1.count(r)
c = counted_tags
counted_tags += quantity_similar_tags
if c < counted_tags:
counted_tags = c + 1
str1 = str1.replace(r, color_dict2[r],quantity_similar_tags)
str1 = str1.replace(r.replace("<","</"), "\033[1;37;40m",quantity_similar_tags)
return str1