hints kitten: Strip prompt mark escape codes

This commit is contained in:
Kovid Goyal 2022-02-15 22:04:10 +05:30
parent 2b495bcf9d
commit 53716c084b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -431,8 +431,9 @@ def load_custom_processor(customize_processing: str) -> Any:
return runpy.run_path(custom_path, run_name='__main__')
def remove_sgr(text: str) -> str:
return re.sub(r'\x1b\[.*?m', '', text)
def remove_escape_codes(text: str) -> str:
# remove SGR and OSC 133 escape codes
return re.sub(r'\x1b(?:\[.*?m|\]133;.*?\x1b\\)', '', text)
def process_hyperlinks(text: str) -> Tuple[str, Tuple[Mark, ...]]:
@ -483,7 +484,7 @@ def process_hyperlinks(text: str) -> Tuple[str, Tuple[Mark, ...]]:
def run(args: HintsCLIOptions, text: str, extra_cli_args: Sequence[str] = ()) -> Optional[Dict[str, Any]]:
try:
text = parse_input(remove_sgr(text))
text = parse_input(remove_escape_codes(text))
text, hyperlinks = process_hyperlinks(text)
pattern, post_processors = functions_for(args)
if args.type == 'linenum':