-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
50 lines (37 loc) · 1.3 KB
/
test.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
import tomllib
from pathlib import Path
def get_xdg_config_path():
try:
config_path = Path("./.config") / \
"alacritty" / "custom.toml"
return config_path
except Exception:
return None
def config_parse(file: Path):
try:
with open(file, "rb") as f:
data = tomllib.load(f)
return data if data else {}
except Exception as e:
print(e)
return {}
path = get_xdg_config_path()
if path:
config = config_parse(path)
colors = ["black", "red", "green", "yellow",
"blue", "magenta", "cyan", "white"]
colors_normal_dict = {k: "" for k in colors}
colors_bright_dict = {k: "" for k in colors}
if config:
for key, value in config["colors"]["normal"].items():
colors_normal_dict[key] = value.replace("0x", "#")
for key, value in config["colors"]["bright"].items():
colors_bright_dict[key] = value.replace("0x", "#")
print(f"background = {config["colors"]["primary"]
["background"].replace("0x", "#")}")
print(f"foreground = {config["colors"]["primary"]
["foreground"].replace("0x", "#")}")
for index, value in enumerate(colors_normal_dict.values()):
print(f"palette = {index}={value}")
for index, value in enumerate(colors_bright_dict.values()):
print(f"palette = {index+8}={value}")