kitty/build-terminfo

47 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python3
2019-03-03 04:54:05 +03:00
import glob
import os
2019-03-03 04:54:05 +03:00
import re
import shutil
import subprocess
2019-03-03 04:54:05 +03:00
import sys
import tempfile
def compile_terminfo(base):
with tempfile.TemporaryDirectory() as tdir:
proc = subprocess.run(['tic', '-x', '-o' + tdir, 'terminfo/kitty.terminfo'], check=True, stderr=subprocess.PIPE)
regex = '^"terminfo/kitty.terminfo", line [0-9]+, col [0-9]+, terminal \'xterm-kitty\': older tic versions may treat the description field as an alias$'
for error in proc.stderr.decode('utf-8').splitlines():
if not re.match(regex, error):
print(error, file=sys.stderr)
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)
2019-03-05 03:24:22 +03:00
odir = os.path.join(base, directory)
2019-03-03 04:54:05 +03:00
os.makedirs(odir, exist_ok=True)
ofile = os.path.join(odir, xterm_kitty)
shutil.move(tfile, 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
2019-03-03 04:54:05 +03:00
with open('terminfo/kitty.terminfo', 'w') as f:
f.write(generate_terminfo())
2019-03-05 03:24:22 +03:00
compile_terminfo(os.path.join(base, 'terminfo'))
2019-03-03 04:54:05 +03:00
if __name__ == '__main__':
generate_terminfo()