Fix hints sometimes matching next line as part of URL

For URLs where there's fewer characters left to the right edge of the
window than the number of escape characters in the line, the next line
would be included in the URL, as if the URL went all the way to the
right edge.

For example with a 40 chars wide terminal, if you run:

    echo -e '\e[31m1\e[m https://github.com/kovidgoyal/kitty\ntest'

And launch the hints kitten, you'll see that test on the next line will
be included in the URL.

This happened because the calculation for filling the rest of the line
with NUL characters counted the escape characters as well as the visible
characters, so it filled in too few characters.

This is a regression introduced in commit 91966712.
This commit is contained in:
Trygve Aaberge
2022-08-30 21:52:27 +02:00
parent fca0999814
commit 03720402a7
2 changed files with 6 additions and 2 deletions

View File

@@ -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'<a href="{u}">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):