From 53716c084bf7156117bdfda590c6c0b06127db2f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 15 Feb 2022 22:04:10 +0530 Subject: [PATCH] hints kitten: Strip prompt mark escape codes --- kittens/hints/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kittens/hints/main.py b/kittens/hints/main.py index bfd0624c2..0719bc738 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -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':