-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-sm-version
executable file
·69 lines (56 loc) · 2.49 KB
/
generate-sm-version
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
#!/usr/bin/env python3
# @todo These shebang'd scripts could instead be `ApplicationCommand`s that run in ST's Python runtime?
# @body Because this API function: https://www.sublimetext.com/docs/api_reference.html#sublime.decode_value
# @body ...is capable of handling JSONC (what I'm currently requiring the `json5` library for).
# This script generates a version of the colour scheme intended for use in the diff pane
# part of Sublime Merge. Why is this necessary when SM can use ST colour schemes as-is?
# Because I don't want full-on programming language syntax highlighting when looking at
# diffs in SM, and it's not currently possible to disable syntax highlighting in SM.
#
# REF: https://github.com/sublimehq/sublime_merge/issues/52
# REF: https://github.com/sublimehq/sublime_merge/issues/198#issuecomment-471042729
import json
from pathlib import Path
import json5
SCHEME_PATH = Path("Humid.sublime-color-scheme")
SMDIFF_SCHEME_PATH = Path("Humid for SM Diff.sublime-color-scheme")
with open(SCHEME_PATH) as infile:
scheme = json5.load(infile)
scheme["name"] = f"{SMDIFF_SCHEME_PATH.stem} (GENERATED FILE - DO NOT EDIT DIRECTLY)"
scheme["variables"].update(
{"kaleidoscope_red": "#4b1512", "kaleidoscope_green": "#2b4e20"}
)
st_background = scheme["globals"]["background"]
st_foreground = scheme["globals"]["foreground"]
# Wholly unchanged lines.
scheme["globals"]["foreground"] = f"color({st_foreground} lightness(- 40%))"
# For the parts of changed lines that didn't change.
def changed_line_foreground(blend_colour):
return f"color({st_foreground} blend({blend_colour} 40%) saturation(+ 5%))"
# For the parts of changed lines that did change.
changed_line_emphasised_foreground = st_foreground
# Replace the existing `rules` array wholesale (not merely adding to it).
scheme["rules"] = [
{
"scope": "diff.deleted",
"background": st_background,
"foreground": changed_line_foreground("var(kaleidoscope_red)"),
},
{
"scope": "diff.deleted.char",
"background": "var(kaleidoscope_red)",
"foreground": changed_line_emphasised_foreground,
},
{
"scope": "diff.inserted",
"background": st_background,
"foreground": changed_line_foreground("var(kaleidoscope_green)"),
},
{
"scope": "diff.inserted.char",
"background": "var(kaleidoscope_green)",
"foreground": changed_line_emphasised_foreground,
},
]
with open(SMDIFF_SCHEME_PATH, "w") as outfile:
json.dump(scheme, outfile, indent=2)