aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate-builtin-terminfo.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/scripts/generate-builtin-terminfo.py b/scripts/generate-builtin-terminfo.py
index acbf5279..61bd4a3c 100755
--- a/scripts/generate-builtin-terminfo.py
+++ b/scripts/generate-builtin-terminfo.py
@@ -50,27 +50,33 @@ class IntCapability(Capability):
class StringCapability(Capability):
def __init__(self, name: str, value: str):
- # Expand \E to literal ESC in non-parameterized capabilities
- 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)
+ # see terminfo(5) for valid escape sequences
- # Replace \E with an actual escape
- value = re.sub(r'\\E', r'\\033', value)
+ # Control characters
+ 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)
- # Don’t escape ‘:’
- value = value.replace('\\:', ':')
+ # Ensure e.g. \E7 (or \e7) doesn’t get translated to “\0337”,
+ # which would be interpreted as octal 337 by the C compiler
+ value = re.sub(r'(\\E|\\e)([0-7])', r'\\033" "\2', value)
- else:
- value = value.replace("\\", "\\\\")
- # # Need to double-escape backslashes. These only occur in
- # # ‘\E\’ combos. Note that \E itself is updated below
- # value = value.replace('\\E\\\\', '\\E\\\\\\\\')
+ # Replace \E and \e with ESC
+ value = re.sub(r'\\E|\\e', r'\\033', value)
+
+ # Unescape ,:^
+ value = re.sub(r'\\(,|:|\^)', r'\1', value)
+
+ # Replace \s with space
+ value = value.replace('\\s', ' ')
- # # Need to double-escape \E in C string literals
- # value = value.replace('\\E', '\\\\E')
+ # Let \\, \n, \r, \t, \b and \f "fall through", to the C string literal
+ if re.search(r'\\l', value):
+ raise NotImplementedError('\\l escape sequence')
super().__init__(name, value)