kitty/build-terminfo
Kovid Goyal 6b681df473
Include all terminfo variants in binary bundles
Needed so that they can be transmitted over ssh easily
2022-03-03 21:24:43 +05:30

56 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
import glob
import os
import re
import shutil
import subprocess
import sys
import tempfile
def compile_terminfo(base, add_other_versions=False):
with tempfile.TemporaryDirectory() as tdir:
proc = subprocess.run(['tic', '-x', f'-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)
odir = os.path.join(base, directory)
os.makedirs(odir, exist_ok=True)
ofile = os.path.join(odir, xterm_kitty)
shutil.move(tfile, ofile)
if add_other_versions:
shutil.copy2('terminfo/kitty.terminfo', base)
for x in os.listdir('terminfo'):
if x == 'kitty.terminfo':
continue
if not os.path.exists(os.path.join(base, x)):
os.symlink(directory, os.path.join(base, x))
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())
compile_terminfo(os.path.join(base, 'terminfo'))
if __name__ == '__main__':
generate_terminfo()