forked from kaste/PyTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
70 lines (54 loc) · 1.68 KB
/
util.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
import sublime
import os
import re
PYTEST_MARKERS = re.compile(r'pytest_is_(red|green)')
PYTEST_RULES = [
{
"class": "status_bar",
"settings": ["pytest_is_green"],
"layer0.tint": [8, 131, 8],
},
{
"class": "label_control",
"settings": ["pytest_is_green"],
"parents": [{"class": "status_bar"}],
"color": [19, 21, 32],
},
{
"class": "status_bar",
"settings": ["pytest_is_red"],
"layer0.tint": [155, 7, 8],
},
{
"class": "label_control",
"settings": ["pytest_is_red"],
"parents": [{"class": "status_bar"}],
"color": [199, 191, 192],
},
]
def tweak_theme():
view = sublime.active_window().active_view()
theme = view.settings().get('theme')
if theme is None:
print("Can't guess current theme.")
return
theme_path = os.path.join(sublime.packages_path(), 'User', theme)
if os.path.exists(theme_path):
with open(theme_path, mode='r', encoding='utf-8') as f:
theme_text = f.read()
if PYTEST_MARKERS.search(theme_text):
print("Already patched")
return
safety_path = os.path.join(
sublime.packages_path(), 'User', 'Original-' + theme)
with open(safety_path, mode='w', encoding='utf-8') as f:
f.write(theme_text)
theme = sublime.decode_value(theme_text)
else:
theme = []
theme.extend(PYTEST_RULES)
tweaked_theme = sublime.encode_value(theme, True)
with open(theme_path, mode='w', encoding='utf-8') as f:
f.write(tweaked_theme)
print('Done tweaking!')
# sublime.active_window().open_file(theme_path)