mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
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:
parent
fd743b5173
commit
f359a8d6bc
1 changed files with 14 additions and 7 deletions
|
|
@ -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 doesn’t 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)
|
||||||
|
|
||||||
|
# Don’t 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')
|
||||||
|
|
||||||
# Don’t escape ‘:’
|
|
||||||
value = value.replace('\\:', ':')
|
|
||||||
|
|
||||||
super().__init__(name, value)
|
super().__init__(name, value)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue