-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
80 lines (59 loc) · 2.23 KB
/
generate.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
77
78
79
80
from pathlib import Path
import json
from data.colors import color_is_bright, blend_colors
DIRNAME = Path(__file__).parent
PALETTES_DIR = DIRNAME / "data" / "palettes"
CONFIGS_DIR = DIRNAME / "data" / "configs"
TARGET_DIR = Path("themes/")
# load the styles
def load_styles(config_name):
with (CONFIGS_DIR / "default.json").open("r") as f:
default_config = json.load(f)
with (CONFIGS_DIR / (config_name + ".json")).open("r") as f:
json_config = json.load(f)
merged_styles = default_config["styles"] | json_config["styles"]
return {
k: (
", modifiers = [{}]".format(", ".join(f'"{mod}"' for mod in v)) if v else ""
)
for (k, v) in merged_styles.items()
}
def generate_derived_colors(palette):
theme_is_light = color_is_bright(palette["base"])
derived_colors = {}
derived_colors["secondary_cursor"] = blend_colors(
palette["base"], palette["rosewater"], 0.7
)
if theme_is_light:
derived_colors["cursorline"] = blend_colors(
palette["base"], palette["mantle"], 0.7
)
else:
derived_colors["cursorline"] = blend_colors(
palette["base"], palette["surface0"], 0.64
)
return derived_colors
def generate_themes():
with (DIRNAME / "data" / "template.tmpl").open("r") as f:
template = f.read()
for config_file in CONFIGS_DIR.glob("*.json"):
config_name = config_file.stem
styles = load_styles(config_name)
(TARGET_DIR / config_name).mkdir(parents=True, exist_ok=True)
for palette_file in PALETTES_DIR.glob("*.json"):
palette_name = palette_file.stem
with palette_file.open("r") as f:
palette = json.load(f)
derived_colors = generate_derived_colors(palette)
with (TARGET_DIR / config_name / (palette_name + ".toml")).open("w") as f:
f.write(
template.format(
**{
"palette": palette,
"styles": styles,
"derived_colors": derived_colors,
}
)
)
if __name__ == "__main__":
generate_themes()