-
-
Notifications
You must be signed in to change notification settings - Fork 986
/
build-terminfo
executable file
·61 lines (50 loc) · 1.95 KB
/
build-terminfo
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
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
import glob
import os
import shutil
import subprocess
import sys
import tempfile
def compile_terminfo(base):
with tempfile.TemporaryDirectory() as tdir:
proc = subprocess.run(['tic', '-x', f'-o{tdir}', 'terminfo/kitty.terminfo'], capture_output=True)
if proc.returncode != 0:
sys.stderr.buffer.write(proc.stderr)
raise SystemExit(proc.returncode)
tfiles = glob.glob(os.path.join(tdir, '*', 'xterm-kitty'))
if not tfiles:
raise SystemExit('tic failed to output the compiled kitty terminfo file')
tfile = tfiles[0]
directory, xterm_kitty = os.path.split(tfile)
_, directory = os.path.split(directory)
odir = os.path.join(base, directory)
os.makedirs(odir, exist_ok=True)
ofile = os.path.join(odir, xterm_kitty)
shutil.move(tfile, ofile)
return ofile
def generate_terminfo():
base = os.path.dirname(os.path.abspath(__file__))
os.chdir(base)
sys.path.insert(0, base)
from kitty.terminfo import generate_terminfo
with open('terminfo/kitty.terminfo', 'w') as f:
f.write(generate_terminfo())
proc = subprocess.run(['tic', '-CrT0', 'terminfo/kitty.terminfo'], capture_output=True)
if proc.returncode != 0:
sys.stderr.buffer.write(proc.stderr)
raise SystemExit(proc.returncode)
tcap = proc.stdout.decode('utf-8').splitlines()[-1]
with open('terminfo/kitty.termcap', 'w') as f:
f.write(tcap)
dbfile = compile_terminfo(os.path.join(base, 'terminfo'))
with open(dbfile, 'rb') as f:
data = f.read()
with open('kitty/terminfo.h', 'w') as f:
print(f'static const uint8_t terminfo_data[{len(data)}] = ''{', file=f)
for b in data:
print(b, end=', ', file=f)
print('};', file=f)
if __name__ == '__main__':
generate_terminfo()