2023-11-11 06:02:05 +03:00
|
|
|
#!/usr/bin/env python
|
2019-05-19 16:41:46 +03:00
|
|
|
# vim:fileencoding=utf-8
|
|
|
|
# License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
|
2016-10-17 15:49:59 +03:00
|
|
|
|
2019-03-03 04:54:05 +03:00
|
|
|
import glob
|
2016-10-17 15:49:59 +03:00
|
|
|
import os
|
2017-01-23 06:26:52 +03:00
|
|
|
import shutil
|
|
|
|
import subprocess
|
2019-03-03 04:54:05 +03:00
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
|
2022-03-10 18:38:20 +03:00
|
|
|
def compile_terminfo(base):
|
2019-03-03 04:54:05 +03:00
|
|
|
with tempfile.TemporaryDirectory() as tdir:
|
2022-04-12 20:08:52 +03:00
|
|
|
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)
|
2019-03-03 04:54:05 +03:00
|
|
|
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
|
2016-11-24 08:59:28 +03:00
|
|
|
|
2019-03-03 04:54:05 +03:00
|
|
|
with open('terminfo/kitty.terminfo', 'w') as f:
|
|
|
|
f.write(generate_terminfo())
|
2022-04-12 20:11:19 +03:00
|
|
|
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)
|
2016-11-24 08:59:28 +03:00
|
|
|
|
2019-03-05 03:24:22 +03:00
|
|
|
compile_terminfo(os.path.join(base, 'terminfo'))
|
2016-11-24 08:59:28 +03:00
|
|
|
|
|
|
|
|
2019-03-03 04:54:05 +03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
generate_terminfo()
|