This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit 3d60c41bf1a896b44fdd530e57be2ee4664baced
Author: Boris Faure <[email protected]>
AuthorDate: Sat Oct 31 09:56:59 2026 +0000
tools: add terminfo_tcap.py to generate an XTGETTCAP table
XTGETTCAP (DCS + q Pt ST) will be answered from the shipped terminfo
entry, so that the entry stays the one document describing what
Terminology does. Generate the table with terminfo_tcap.py; nothing
includes the header yet.
---
DEV.md | 9 ++
src/bin/meson.build | 4 +
src/bin/termptytcap.h | 285 +++++++++++++++++++++++++++++++++++++++++++++++++
tools/terminfo_tcap.py | 214 +++++++++++++++++++++++++++++++++++++
4 files changed, 512 insertions(+)
diff --git a/DEV.md b/DEV.md
index ea1cf1d6..47055591 100644
--- a/DEV.md
+++ b/DEV.md
@@ -8,3 +8,12 @@ This is done by using `tools/unicode_dbl_width.py`.
2. Extract it
3. Run `tools/unicode_dbl_width.py ucd.all.flat.xml src/bin/termptydbl.h src/bin/termptydbl.c`_
4. Commit the files modified
+
+# Terminfo capabilities
+
+The table that answers XTGETTCAP queries is generated from the shipped
+terminfo entry, so that the two cannot drift apart.
+
+After editing `data/terminfo/terminology.terminfo`, run
+`tools/terminfo_tcap.py data/terminfo/terminology.terminfo src/bin/termptytcap.h`
+and commit both files.
diff --git a/src/bin/meson.build b/src/bin/meson.build
index cc0c7b1c..3e0d0ba1 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -42,6 +42,7 @@ terminology_sources = ['private.h',
'termiolink.c', 'termiolink.h',
'termpty.c', 'termpty.h',
'termptydbl.c', 'termptydbl.h',
+ 'termptytcap.h',
'termptyesc.c', 'termptyesc.h',
'termptyops.c', 'termptyops.h',
'termptygfx.c', 'termptygfx.h',
@@ -71,6 +72,7 @@ tyfuzz_sources = [color_names,
'backlog.c', 'backlog.h',
'termptyops.c', 'termptyops.h',
'termptydbl.c', 'termptydbl.h',
+ 'termptytcap.h',
'termptyext.c', 'termptyext.h',
'termptygfx.c', 'termptygfx.h',
'termpty.c', 'termpty.h',
@@ -91,6 +93,7 @@ tytest_sources = [color_names,
'backlog.c', 'backlog.h',
'termptyops.c', 'termptyops.h',
'termptydbl.c', 'termptydbl.h',
+ 'termptytcap.h',
'termptyext.c', 'termptyext.h',
'termptygfx.c', 'termptygfx.h',
'termpty.c', 'termpty.h',
@@ -117,6 +120,7 @@ tybench_sources = [color_names,
'backlog.c', 'backlog.h',
'termptyops.c', 'termptyops.h',
'termptydbl.c', 'termptydbl.h',
+ 'termptytcap.h',
'termptyext.c', 'termptyext.h',
'termptygfx.c', 'termptygfx.h',
'termpty.c', 'termpty.h',
diff --git a/src/bin/termptytcap.h b/src/bin/termptytcap.h
new file mode 100644
index 00000000..12c9b619
--- /dev/null
+++ b/src/bin/termptytcap.h
@@ -0,0 +1,285 @@
+/* XXX: Code generated by tool terminfo_tcap.py */
+#ifndef TERMINOLOGY_TERMPTY_TCAP_H_
+#define TERMINOLOGY_TERMPTY_TCAP_H_ 1
+
+typedef struct _Termpty_Tcap
+{
+ const char *name;
+ const char *value; /* NULL for a boolean */
+} Termpty_Tcap;
+
+static const Termpty_Tcap _termpty_tcaps[] =
+{
+ { "AX", NULL },
+ { "Clmg", "\033[s" },
+ { "Cmg", "\033[%i%p1%d;%p2%ds" },
+ { "Co", "256" },
+ { "Cr", "\033]112\007" },
+ { "Cs", "\033]12;%p1%s\007" },
+ { "Dsbp", "\033[?2004l" },
+ { "Dseks", "\033[>4m" },
+ { "Dsfcs", "\033[?1004l" },
+ { "E3", "\033[3J" },
+ { "Enbp", "\033[?2004h" },
+ { "Eneks", "\033[>4;2m" },
+ { "Enfcs", "\033[?1004h" },
+ { "Hls", "\033]8;%?%p1%l%tid=%p1%s%;;%p2%s\033\134" },
+ { "Ms", "\033]52;%p1%s;%p2%s\007" },
+ { "OTbs", NULL },
+ { "RV", "\033[>c" },
+ { "Rect", "\033" },
+ { "Se", "\033[2 q" },
+ { "Ss", "\033[%p1%d q" },
+ { "Swd", "\033]7;" },
+ { "Sync", "\033[?2026%?%p1%{1}%-%tl%eh%;" },
+ { "Tc", NULL },
+ { "XF", NULL },
+ { "XM", "\033[?1006;1000%?%p1%{1}%=%th%el%;" },
+ { "XR", "\033[>0q" },
+ { "XT", NULL },
+ { "acsc", "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~" },
+ { "am", NULL },
+ { "bce", NULL },
+ { "bel", "\007" },
+ { "blink", "\033[5m" },
+ { "bold", "\033[1m" },
+ { "cbt", "\033[Z" },
+ { "civis", "\033[?25l" },
+ { "clear", "\033[H\033[2J" },
+ { "cnorm", "\033[?25h" },
+ { "colors", "256" },
+ { "cols", "80" },
+ { "cr", "\015" },
+ { "csr", "\033[%i%p1%d;%p2%dr" },
+ { "cub", "\033[%p1%dD" },
+ { "cub1", "\010" },
+ { "cud", "\033[%p1%dB" },
+ { "cud1", "\012" },
+ { "cuf", "\033[%p1%dC" },
+ { "cuf1", "\033[C" },
+ { "cup", "\033[%i%p1%d;%p2%dH" },
+ { "cuu", "\033[%p1%dA" },
+ { "cuu1", "\033[A" },
+ { "dch", "\033[%p1%dP" },
+ { "dch1", "\033[P" },
+ { "dim", "\033[2m" },
+ { "dl", "\033[%p1%dM" },
+ { "dl1", "\033[M" },
+ { "dsl", "\033]0;\007" },
+ { "ech", "\033[%p1%dX" },
+ { "ed", "\033[J" },
+ { "el", "\033[K" },
+ { "el1", "\033[1K" },
+ { "fd", "\033[?1004l" },
+ { "fe", "\033[?1004h" },
+ { "fsl", "\007" },
+ { "home", "\033[H" },
+ { "hpa", "\033[%i%p1%dG" },
+ { "hs", NULL },
+ { "ht", "\011" },
+ { "hts", "\033H" },
+ { "ich", "\033[%p1%d@" },
+ { "il", "\033[%p1%dL" },
+ { "il1", "\033[L" },
+ { "ind", "\012" },
+ { "indn", "\033[%p1%dS" },
+ { "invis", "\033[8m" },
+ { "is2", "\033[!p\033[?3;4l\033[4l\033>" },
+ { "it", "8" },
+ { "kDC", "\033[3;2~" },
+ { "kDC3", "\033[3;3~" },
+ { "kDC4", "\033[3;4~" },
+ { "kDC5", "\033[3;5~" },
+ { "kDC6", "\033[3;6~" },
+ { "kDC7", "\033[3;7~" },
+ { "kDN", "\033[1;2B" },
+ { "kDN3", "\033[1;3B" },
+ { "kDN4", "\033[1;4B" },
+ { "kDN5", "\033[1;5B" },
+ { "kDN6", "\033[1;6B" },
+ { "kDN7", "\033[1;7B" },
+ { "kEND", "\033[1;2F" },
+ { "kEND3", "\033[1;3F" },
+ { "kEND4", "\033[1;4F" },
+ { "kEND5", "\033[1;5F" },
+ { "kEND6", "\033[1;6F" },
+ { "kEND7", "\033[1;7F" },
+ { "kHOM", "\033[1;2H" },
+ { "kHOM3", "\033[1;3H" },
+ { "kHOM4", "\033[1;4H" },
+ { "kHOM5", "\033[1;5H" },
+ { "kHOM6", "\033[1;6H" },
+ { "kHOM7", "\033[1;7H" },
+ { "kIC", "\033[2;2~" },
+ { "kIC3", "\033[2;3~" },
+ { "kIC4", "\033[2;4~" },
+ { "kIC5", "\033[2;5~" },
+ { "kIC6", "\033[2;6~" },
+ { "kIC7", "\033[2;7~" },
+ { "kLFT", "\033[1;2D" },
+ { "kLFT3", "\033[1;3D" },
+ { "kLFT4", "\033[1;4D" },
+ { "kLFT5", "\033[1;5D" },
+ { "kLFT6", "\033[1;6D" },
+ { "kLFT7", "\033[1;7D" },
+ { "kNXT", "\033[6;2~" },
+ { "kNXT3", "\033[6;3~" },
+ { "kNXT4", "\033[6;4~" },
+ { "kNXT5", "\033[6;5~" },
+ { "kNXT6", "\033[6;6~" },
+ { "kNXT7", "\033[6;7~" },
+ { "kPRV", "\033[5;2~" },
+ { "kPRV3", "\033[5;3~" },
+ { "kPRV4", "\033[5;4~" },
+ { "kPRV5", "\033[5;5~" },
+ { "kPRV6", "\033[5;6~" },
+ { "kPRV7", "\033[5;7~" },
+ { "kRIT", "\033[1;2C" },
+ { "kRIT3", "\033[1;3C" },
+ { "kRIT4", "\033[1;4C" },
+ { "kRIT5", "\033[1;5C" },
+ { "kRIT6", "\033[1;6C" },
+ { "kRIT7", "\033[1;7C" },
+ { "kUP", "\033[1;2A" },
+ { "kUP3", "\033[1;3A" },
+ { "kUP4", "\033[1;4A" },
+ { "kUP5", "\033[1;5A" },
+ { "kUP6", "\033[1;6A" },
+ { "kUP7", "\033[1;7A" },
+ { "kbs", "\177" },
+ { "kcbt", "\033[Z" },
+ { "kcub1", "\033OD" },
+ { "kcud1", "\033OB" },
+ { "kcuf1", "\033OC" },
+ { "kcuu1", "\033OA" },
+ { "kdch1", "\033[3~" },
+ { "kend", "\033OF" },
+ { "kf1", "\033OP" },
+ { "kf10", "\033[21~" },
+ { "kf11", "\033[23~" },
+ { "kf12", "\033[24~" },
+ { "kf13", "\033[1;2P" },
+ { "kf14", "\033[1;2Q" },
+ { "kf15", "\033[1;2R" },
+ { "kf16", "\033[1;2S" },
+ { "kf17", "\033[15;2~" },
+ { "kf18", "\033[17;2~" },
+ { "kf19", "\033[18;2~" },
+ { "kf2", "\033OQ" },
+ { "kf20", "\033[19;2~" },
+ { "kf21", "\033[20;2~" },
+ { "kf22", "\033[21;2~" },
+ { "kf23", "\033[23;2~" },
+ { "kf24", "\033[24;2~" },
+ { "kf25", "\033[1;5P" },
+ { "kf26", "\033[1;5Q" },
+ { "kf27", "\033[1;5R" },
+ { "kf28", "\033[1;5S" },
+ { "kf29", "\033[15;5~" },
+ { "kf3", "\033OR" },
+ { "kf30", "\033[17;5~" },
+ { "kf31", "\033[18;5~" },
+ { "kf32", "\033[19;5~" },
+ { "kf33", "\033[20;5~" },
+ { "kf34", "\033[21;5~" },
+ { "kf35", "\033[23;5~" },
+ { "kf36", "\033[24;5~" },
+ { "kf37", "\033[1;6P" },
+ { "kf38", "\033[1;6Q" },
+ { "kf39", "\033[1;6R" },
+ { "kf4", "\033OS" },
+ { "kf40", "\033[1;6S" },
+ { "kf41", "\033[15;6~" },
+ { "kf42", "\033[17;6~" },
+ { "kf43", "\033[18;6~" },
+ { "kf44", "\033[19;6~" },
+ { "kf45", "\033[20;6~" },
+ { "kf46", "\033[21;6~" },
+ { "kf47", "\033[23;6~" },
+ { "kf48", "\033[24;6~" },
+ { "kf49", "\033[1;3P" },
+ { "kf5", "\033[15~" },
+ { "kf50", "\033[1;3Q" },
+ { "kf51", "\033[1;3R" },
+ { "kf52", "\033[1;3S" },
+ { "kf53", "\033[15;3~" },
+ { "kf54", "\033[17;3~" },
+ { "kf55", "\033[18;3~" },
+ { "kf56", "\033[19;3~" },
+ { "kf57", "\033[20;3~" },
+ { "kf58", "\033[21;3~" },
+ { "kf59", "\033[23;3~" },
+ { "kf6", "\033[17~" },
+ { "kf60", "\033[24;3~" },
+ { "kf61", "\033[1;4P" },
+ { "kf62", "\033[1;4Q" },
+ { "kf63", "\033[1;4R" },
+ { "kf7", "\033[18~" },
+ { "kf8", "\033[19~" },
+ { "kf9", "\033[20~" },
+ { "khome", "\033OH" },
+ { "kich1", "\033[2~" },
+ { "kind", "\033[1;2B" },
+ { "kmous", "\033[<" },
+ { "knp", "\033[6~" },
+ { "kpp", "\033[5~" },
+ { "kri", "\033[1;2A" },
+ { "kxIN", "\033[I" },
+ { "kxOUT", "\033[O" },
+ { "lines", "24" },
+ { "mc0", "\033[i" },
+ { "mc4", "\033[4i" },
+ { "mc5", "\033[5i" },
+ { "mc5i", NULL },
+ { "meml", "\033l" },
+ { "memu", "\033m" },
+ { "mir", NULL },
+ { "msgr", NULL },
+ { "op", "\033[39;49m" },
+ { "pairs", "65536" },
+ { "rc", "\0338" },
+ { "rep", "%p1%c\033[%p2%{1}%-%db" },
+ { "rev", "\033[7m" },
+ { "ri", "\033M" },
+ { "rin", "\033[%p1%dT" },
+ { "ritm", "\033[23m" },
+ { "rmacs", "\033(B" },
+ { "rmam", "\033[?7l" },
+ { "rmcup", "\033[?1049l\033[23;0;0t" },
+ { "rmir", "\033[4l" },
+ { "rmkx", "\033[?1l\033>" },
+ { "rmso", "\033[27m" },
+ { "rmul", "\033[24m" },
+ { "rmxx", "\033[29m" },
+ { "rs1", "\033c" },
+ { "rs2", "\033[!p\033[?3;4l\033[4l\033>" },
+ { "rv", "\033\134[>[0-9]+;[0-9]+;[0-9]+c" },
+ { "sc", "\0337" },
+ { "setab", "\033[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m" },
+ { "setaf", "\033[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m" },
+ { "setrgbb", "\033[48;2;%p1%d;%p2%d;%p3%dm" },
+ { "setrgbf", "\033[38;2;%p1%d;%p2%d;%p3%dm" },
+ { "sgr", "%?%p9%t\033(0%e\033(B%;\033[0%?%p6%t;1%;%?%p5%t;2%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m" },
+ { "sgr0", "\033(B\033[m" },
+ { "sitm", "\033[3m" },
+ { "smacs", "\033(0" },
+ { "smam", "\033[?7h" },
+ { "smcup", "\033[?1049h\033[22;0;0t" },
+ { "smir", "\033[4h" },
+ { "smkx", "\033[?1h\033=" },
+ { "smso", "\033[7m" },
+ { "smul", "\033[4m" },
+ { "smxx", "\033[9m" },
+ { "tbc", "\033[3g" },
+ { "tsl", "\033]0;" },
+ { "u6", "\033[%i%d;%dR" },
+ { "u7", "\033[6n" },
+ { "u8", "\033[?%[;0123456789]c" },
+ { "u9", "\033[c" },
+ { "vpa", "\033[%i%p1%dd" },
+ { "xenl", NULL },
+ { "xm", "\033[<%i%p3%d;%p1%d;%p2%d;%?%p4%tM%em%;" },
+ { "xr", "\033P>\134|[ -~]+\033\134\134" },
+};
+
+#endif
diff --git a/tools/terminfo_tcap.py b/tools/terminfo_tcap.py
new file mode 100644
index 00000000..5fc3f65f
--- /dev/null
+++ b/tools/terminfo_tcap.py
@@ -0,0 +1,214 @@
+#!/usr/bin/env python3
+
+"""
+Generate src/bin/termptytcap.h from data/terminfo/terminology.terminfo.
+
+The header holds the table the XTGETTCAP query (DCS + q Pt ST, see
+<https://invisible-island.net/xterm/ctlseqs/ctlseqs.html>) is answered
+from: every capability of the shipped terminfo entry, sorted with C
+strcmp() order so that bsearch() works.
+
+The terminfo entry is the document that says what Terminology does, so
+the table is generated from it rather than hand-picked; run this script
+after editing the entry and commit both files:
+
+ tools/terminfo_tcap.py data/terminfo/terminology.terminfo \
+ src/bin/termptytcap.h
+
+With --check, regenerate to memory and exit 1 if the committed file
+differs.
+"""
+
+import argparse
+import sys
+
+# terminfo(5) escapes in string capabilities. \a is not in the classic
+# set but ncurses accepts it, and the shipped entry uses it in Ms.
+SIMPLE_ESCAPES = {
+ 'E': 0x1b, 'e': 0x1b,
+ 'n': 0x0a, 'l': 0x0a,
+ 'r': 0x0d, 't': 0x09,
+ 'b': 0x08, 'f': 0x0c,
+ 's': 0x20,
+ 'a': 0x07,
+ '\\': 0x5c, ',': 0x2c, ':': 0x3a, '^': 0x5e,
+}
+
+
+def decode_string(s, capname):
+ """Decode a terminfo string capability to its runtime bytes."""
+ out = bytearray()
+ i = 0
+ while i < len(s):
+ c = s[i]
+ if c == '\\':
+ i += 1
+ if i >= len(s):
+ raise ValueError(f'{capname}: trailing backslash in {s!r}')
+ e = s[i]
+ if e in SIMPLE_ESCAPES:
+ out.append(SIMPLE_ESCAPES[e])
+ i += 1
+ elif e.isdigit():
+ # \NNN is octal, at most three digits. A NUL byte,
+ # however it is spelled, becomes \200 as ncurses does,
+ # so that it cannot truncate the C string.
+ j = i
+ while (j < len(s)) and (j < i + 3) and s[j].isdigit():
+ j += 1
+ digits = s[i:j]
+ value = int(digits, 8) & 0xff
+ out.append(0x80 if value == 0 else value)
+ i = j
+ else:
+ raise ValueError(f'{capname}: unknown escape \\{e} in {s!r}')
+ elif c == '^':
+ i += 1
+ if i >= len(s):
+ raise ValueError(f'{capname}: trailing ^ in {s!r}')
+ e = s[i]
+ if e == '?':
+ out.append(0x7f)
+ elif e == '@':
+ out.append(0x80)
+ else:
+ out.append(ord(e.upper()) & 0x1f)
+ i += 1
+ else:
+ out.append(ord(c))
+ i += 1
+ return bytes(out)
+
+
+def split_fields(body):
+ """Split on commas, where \\, is not a separator."""
+ fields = []
+ start = 0
+ escaped = False
+ for i, c in enumerate(body):
+ if escaped:
+ escaped = False
+ elif c == '\\':
+ escaped = True
+ elif c == ',':
+ fields.append(body[start:i])
+ start = i + 1
+ tail = body[start:]
+ if tail.strip():
+ fields.append(tail)
+ return fields
+
+
+def parse_terminfo(path):
+ """Return {name: bytes or None} for every non-cancelled capability."""
+ caps = {}
+ with open(path, 'r', encoding='utf-8') as f:
+ text = f.read()
+
+ # Drop comment lines, then the first field, the names.
+ lines = [ln for ln in text.splitlines()
+ if ln.strip() and not ln.strip().startswith('#')]
+ if not lines:
+ raise ValueError('empty terminfo source')
+ fields = split_fields(''.join(lines))
+ if not fields:
+ raise ValueError('no capabilities found')
+
+ for field in fields[1:]:
+ field = field.strip()
+ if not field:
+ continue
+ eq = field.find('=')
+ hash_ = field.find('#')
+ if field.endswith('@') and (eq < 0) and (hash_ < 0):
+ continue # cancelled capability
+ if (eq >= 0) and ((hash_ < 0) or (eq < hash_)):
+ name = field[:eq]
+ caps[name] = decode_string(field[eq + 1:], name)
+ elif hash_ >= 0:
+ name = field[:hash_]
+ caps[name] = str(int(field[hash_ + 1:], 0)).encode('ascii')
+ else:
+ name = field
+ caps[name] = None # boolean
+ if name == 'use':
+ raise ValueError('use= entries are not supported')
+
+ if 'colors' not in caps:
+ raise ValueError('colors# is missing from the entry')
+ # Co is the termcap spelling of colors, always asked as Co.
+ caps['Co'] = caps['colors']
+ return caps
+
+
+def c_quote(b):
+ """A C string literal for the bytes, octal escapes three digits wide."""
+ if 0 in b:
+ raise ValueError('a NUL byte would truncate the C string')
+ out = []
+ for byte in b:
+ if (0x20 <= byte < 0x7f) and byte not in (0x22, 0x5c):
+ out.append(chr(byte))
+ else:
+ out.append(f'\\{byte:03o}')
+ return '"' + ''.join(out) + '"'
+
+
+def generate_header(caps):
+ lines = [
+ '/* XXX: Code generated by tool terminfo_tcap.py */',
+ '#ifndef TERMINOLOGY_TERMPTY_TCAP_H_',
+ '#define TERMINOLOGY_TERMPTY_TCAP_H_ 1',
+ ]
+ lines.extend([
+ '',
+ 'typedef struct _Termpty_Tcap',
+ '{',
+ ' const char *name;',
+ ' const char *value; /* NULL for a boolean */',
+ '} Termpty_Tcap;',
+ '',
+ 'static const Termpty_Tcap _termpty_tcaps[] =',
+ '{',
+ ])
+ for name in sorted(caps):
+ value = caps[name]
+ if value is None:
+ lines.append(f' {{ {c_quote(name.encode("ascii"))}, NULL }},')
+ else:
+ lines.append(f' {{ {c_quote(name.encode("ascii"))}, '
+ f'{c_quote(value)} }},')
+ lines.extend([
+ '};',
+ '',
+ '#endif',
+ '',
+ ])
+ return '\n'.join(lines)
+
+
+def main():
+ ap = argparse.ArgumentParser(description=__doc__)
+ ap.add_argument('terminfo')
+ ap.add_argument('output')
+ ap.add_argument('--check', action=""
+ help='compare with the committed file instead of writing')
+ args = ap.parse_args()
+
+ content = generate_header(parse_terminfo(args.terminfo))
+ if args.check:
+ with open(args.output, 'r', encoding='utf-8') as f:
+ committed = f.read()
+ if committed != content:
+ print(f'{args.output} is out of date: run '
+ f'tools/terminfo_tcap.py {args.terminfo} {args.output} '
+ 'and commit both files', file=sys.stderr)
+ return 1
+ return 0
+ with open(args.output, 'w', encoding='utf-8') as f:
+ f.write(content)
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.