forked from baverman/vim-babymate256
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.py
executable file
·81 lines (60 loc) · 2.08 KB
/
make.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 python2
import sys
import os.path
import argparse
import shutil
from mako.template import Template
import tcolor
def make_hi(use_bold=True):
colors = set()
def get_256_color(color):
c256 = tcolor.find_nearest(color)[1]
colors.add((int(c256), color.upper()))
return c256
def hi(fg=None, bg=None, bold=None, italic=None, underline=None, reverse=None):
parts = []
if fg:
parts.append(('guifg', '#' + fg))
parts.append(('ctermfg', get_256_color(fg)))
if bg:
parts.append(('guibg', '#' + bg))
parts.append(('ctermbg', get_256_color(bg)))
attrs = []
if use_bold and bold:
attrs.append('bold')
if italic:
attrs.append('italic')
if underline:
attrs.append('underline')
if reverse:
attrs.append('reverse')
if not attrs:
attrs.append('none')
if attrs:
cattrs = ','.join(attrs)
parts.append(('gui', cattrs))
parts.append(('cterm', cattrs))
return ' '.join('{}={}'.format(*r) for r in parts)
bgfix = lambda bg: r'\033]11;#{}\007'.format(bg)
cfix = lambda: r'\033]4;{}\007'.format(
';'.join('{};#{}'.format(*r) for r in sorted(colors)))
hi.xterm = lambda bg: bgfix(bg) + cfix()
hi.urxvt = cfix
hi.cterm = get_256_color
return hi
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Render vim colorscheme file')
parser.add_argument('--disable-bold', dest='use_bold',
action='store_false', default=True)
parser.add_argument('template', nargs='+')
args = parser.parse_args()
hi = make_hi(args.use_bold)
theme_tpl = None
for fname in args.template:
tpl = Template(filename=fname)
outname = os.path.expanduser(tpl.module.out)
with open(outname, 'w') as f:
f.write(tpl.render(hi=hi, cterm=hi.cterm, theme_tpl=theme_tpl))
shutil.copymode(fname, outname)
if not theme_tpl:
theme_tpl = tpl.module