-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimcolors2gui.py
67 lines (55 loc) · 1.87 KB
/
vimcolors2gui.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
#!/usr/bin/env python3
from sys import argv
from re import compile as regexp
from config import lookup
REGEX_HIGHLIGHT = regexp(r"^hi\s+(\w+)\s+(.*)")
REGEX_PARAM = regexp(r"(\w+)=([^\s]+)")
palette = {
"name": "",
"author": "",
"color": [
lookup('color.{}'.format(i)) for i in range(16)
],
"foreground": "#658798",
"background": "#1e2138"
}
BRIGHTNESS_LUT = [ 0x00, 0x66, 0x88, 0xbb, 0xdd, 0xff ]
def pal256torgb(index):
if index >= 232 and index <= 255:
value = int(((index - 232) / 24) * 255)
return "#%02x%02x%02x" % (value, value, value)
elif index <= 15:
return palette["color"][index]
else:
index -= 16
b = BRIGHTNESS_LUT[index % 6]
index //= 6
g = BRIGHTNESS_LUT[index % 6]
index //= 6
r = BRIGHTNESS_LUT[index % 6]
return "#%02x%02x%02x" % (r, g, b)
with open(argv[1], "r") as f_in:
for line in f_in:
line = line.strip()
if (match := REGEX_HIGHLIGHT.match(line)):
syntax, options = match.groups()
options = dict(REGEX_PARAM.findall(options))
if (ctermfg := options.get('ctermfg')):
if ctermfg == 'NONE':
options['guifg'] = 'NONE'
else:
options['guifg'] = pal256torgb(int(ctermfg))
if (ctermbg := options.get('ctermbg')):
if ctermbg == 'NONE':
options['guibg'] = 'NONE'
else:
options['guibg'] = pal256torgb(int(ctermbg))
if (cterm := options.get('cterm')):
options['gui'] = cterm
options_str = str.join(' ', [
'%-16s' % ('%s=%s' % (k, v))
for k, v in options.items()
]).strip()
print('%-24s' % ('hi %s' % syntax), options_str)
else:
print(line)