diff --git a/kittens/hints/main.py b/kittens/hints/main.py index 01fa9384b..42a2568b3 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -411,7 +411,8 @@ def convert_text(text: str, cols: int) -> str: appended = False for line in full_line.split('\r'): if line: - lines.append(line.ljust(cols, '\0')) + escape_codes_len = sum([len(match) for match in kitty_ansi_sanitizer_pat().findall(line)]) + lines.append(line.ljust(cols + escape_codes_len, '\0')) lines.append('\r') appended = True if appended: diff --git a/kitty_tests/hints.py b/kitty_tests/hints.py index c232b97e1..0811fd23a 100644 --- a/kitty_tests/hints.py +++ b/kitty_tests/hints.py @@ -10,13 +10,14 @@ class TestHints(BaseTest): def test_url_hints(self): from kittens.hints.main import ( Mark, convert_text, functions_for, linenum_marks, - linenum_process_result, mark, parse_hints_args + linenum_process_result, mark, parse_hints_args, process_escape_codes ) args = parse_hints_args([])[0] pattern, post_processors = functions_for(args) def create_marks(text, cols=20, mark=mark): text = convert_text(text, cols) + text, _ = process_escape_codes(text) return tuple(mark(pattern, post_processors, text, args)) def t(text, url, cols=20): @@ -32,6 +33,8 @@ class TestHints(BaseTest): t(f'link:{u}[xxx]', u) t(f'`xyz <{u}>`_.', u) t(f'moo', u) + t('\x1b[mhttp://test.me/1234\n\x1b[mx', 'http://test.me/1234') + t('\x1b[mhttp://test.me/12345\r\x1b[m6\n\x1b[mx', 'http://test.me/123456') def m(text, path, line, cols=20):