scripts: generate-builtin-terminfo: use \xNN for control characters

Instead of emitting raw control characters (for e.g. bel, cub1 and
kbs), use \xNN C string escapes.
This commit is contained in:
Daniel Eklöf 2024-04-30 10:50:31 +02:00
parent a3debf7741
commit 3c4669061b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -56,9 +56,9 @@ class StringCapability(Capability):
def translate_ctrl_chr(m):
ctrl = m.group(1)
if ctrl == '?':
return chr(0x7f)
return chr(ord(ctrl) - ord('@'))
value = re.sub('\^([@A-Z[\\\\\]^_?])', translate_ctrl_chr, value)
return '\\x7f'
return f'\\x{ord(ctrl) - ord('@'):02x}'
value = re.sub(r'\^([@A-Z[\\\\\]^_?])', translate_ctrl_chr, value)
# Ensure e.g. \E7 (or \e7) doesnt get translated to “\0337”,
# which would be interpreted as octal 337 by the C compiler