-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.py
executable file
·81 lines (67 loc) · 2.04 KB
/
build.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
81
#!/usr/bin/env python3
import json
import re
import itertools
from adwaita_colors import get_adwaita_colors
from adwaita_ui_colors import get_adwaita_ui_colors
def load_jsonc(path):
'''Read JSON with comments.'''
original = open(path).read()
stripped = re.sub(r'[^:]//.+$', '', original, flags=re.MULTILINE)
return json.loads(stripped)
def get_default_syntax_colors(theme_type):
return load_jsonc(f'default_themes/{theme_type}.jsonc')['tokenColors']
extra_syntax_colors = [
{
'scope': ['markup.italic.markdown'],
'settings': {
'fontStyle': 'italic'
}
},
{
'scope': ['markup.strikethrough.markdown'],
'settings': {
'fontStyle': 'strikethrough'
}
}
]
package_json_entry = {
'contributes': {
'themes': []
}
}
for (
theme_type,
syntax_colors_type,
colorful_status_bar
) in itertools.product(
('dark', 'light'),
('adwaita', 'default'),
(False, True)
):
name = f'Adwaita {theme_type.capitalize()}'
ui_colors = get_adwaita_ui_colors(theme_type, colorful_status_bar)
if syntax_colors_type == 'adwaita':
_named_colors, syntax_colors = get_adwaita_colors(theme_type)
syntax_colors += extra_syntax_colors
else:
syntax_colors = get_default_syntax_colors(theme_type)
name += ' & default syntax highlighting'
if colorful_status_bar:
name += ' & colorful status bar'
theme = {
'$schema': 'vscode://schemas/color-theme',
'name': name,
'type': 'light',
'colors': ui_colors,
'tokenColors': syntax_colors
}
file_name = f'{name.lower().replace(" ", "-").replace("-&-", "-")}.json'
json.dump(theme, open(f'../themes/{file_name}', 'w'), indent=2)
package_json_entry['contributes']['themes'].append({
'label': name,
'uiTheme': 'vs-dark' if theme_type == 'dark' else 'vs',
'path': f'./themes/{file_name}'
})
print('Suggested package.json entry:')
print(json.dumps(package_json_entry, indent=2)[2:-2])