-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.py
72 lines (56 loc) · 2.38 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
from colorama import init, Fore
import re
init(autoreset=True)
RED = Fore.RED #"\x1b[31m"
GREEN = Fore.GREEN #"\x1b[32m"
CYAN = Fore.CYAN #"\x1b[96m"
YELLOW = Fore.YELLOW #"\x1b[33m"
MAGENTA = Fore.MAGENTA #"\x1b[95m"
ORANGE = "\x1b[38;2;255;165;0m"
RESET = Fore.RESET #"\x1b[0m"
class Color():
def __init__(self) -> None:
self.word_list = [
"name:",
"gabc-copyright:",
"score-copyright:",
"office-part:",
"occasion:",
"meter:",
"commentary:",
"arranger:",
"author:",
"date:",
"manuscript:",
"manuscript-reference:",
"manuscript-storage-place:",
"book:",
"language:",
"transcriber:",
"transcription-date:",
"mode:",
"mode-differentia:",
"user-notes:",
"annotation:",
]
def color_text(self, filegabc):
content = str(filegabc)
# Remplacer "%%" par sa version colorée
content = content.replace("%%", GREEN + "%%")
pos = content.find("%%")
before = content[:pos + 2]
after = content[pos + 2:]
# Remplacement des mots en tenant compte de la casse
before = before.replace(';', ORANGE + ';' + RESET)
for word in self.word_list:
before = before.replace(word, ORANGE + word+ RESET )
after = re.sub(r"(\s?.*?)(\(.*?\)\n?)", ORANGE + r"\1" + RESET + r"\2", after)
after = re.sub(r"(\(.*?\))", CYAN + r"\1" + RESET, after)
after = re.sub(r"(\*)", RED + r"\1" + RESET, after)
after = re.sub(r"(\((c2|c3|c4|f3|f4|cb3|c2@c4)\))", YELLOW + r"\1" + RESET, after)
after = re.sub(r"(\((;|::|,|;3|;4|;6)\))", YELLOW + r"\1" + RESET, after)
#after = re.sub(r"(\[|\])", MAGENTA + r"\1" + RESET, after)
after = re.sub(r"(<[/]?eu>)", MAGENTA + r"\1" + RESET, after)
content = before + after
print(GREEN+"[info]"+RESET+" Result:\n")
print(content)