scripts: generate-builtin-terminfo: escape fixes

* Remove ‘:’ escaping only in raw (non-parameterized) sequences
* Double-escape *all* escape characters in parameterized sequences
This commit is contained in:
Daniel Eklöf 2022-10-04 21:42:13 +02:00
parent fd743b5173
commit f359a8d6bc
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -52,18 +52,25 @@ class StringCapability(Capability):
def __init__(self, name: str, value: str): def __init__(self, name: str, value: str):
# Expand \E to literal ESC in non-parameterized capabilities # Expand \E to literal ESC in non-parameterized capabilities
if '%' not in value: if '%' not in value:
# Ensure e.g. \E7 doesnt get translated to “\0337”, which
# would be interpreted as octal 337 by the C compiler
value = re.sub(r'\\E([0-7])', r'\\033" "\1', value) value = re.sub(r'\\E([0-7])', r'\\033" "\1', value)
# Replace \E with an actual escape
value = re.sub(r'\\E', r'\\033', value) value = re.sub(r'\\E', r'\\033', value)
# Dont escape :
value = value.replace('\\:', ':')
else: else:
# Need to double-escape backslashes. These only occur in value = value.replace("\\", "\\\\")
# \E\ combos. Note that \E itself is updated below # # Need to double-escape backslashes. These only occur in
value = value.replace('\\E\\\\', '\\E\\\\\\\\') # # \E\ combos. Note that \E itself is updated below
# value = value.replace('\\E\\\\', '\\E\\\\\\\\')
# Need to double-escape \E in C string literals # # Need to double-escape \E in C string literals
value = value.replace('\\E', '\\\\E') # value = value.replace('\\E', '\\\\E')
# Dont escape :
value = value.replace('\\:', ':')
super().__init__(name, value) super().__init__(name, value)