mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Make hyperlinked_grep kitten respect context
Fix regex so that context lines (from -C option) are still hyperlinked. Also add a case so that any non-matching lines are still output raw.
This commit is contained in:
@@ -29,7 +29,7 @@ def main() -> None:
|
|||||||
write: Callable[[bytes], None] = cast(Callable[[bytes], None], sys.stdout.buffer.write)
|
write: Callable[[bytes], None] = cast(Callable[[bytes], None], sys.stdout.buffer.write)
|
||||||
sgr_pat = re.compile(br'\x1b\[.*?m')
|
sgr_pat = re.compile(br'\x1b\[.*?m')
|
||||||
osc_pat = re.compile(b'\x1b\\].*?\x1b\\\\')
|
osc_pat = re.compile(b'\x1b\\].*?\x1b\\\\')
|
||||||
num_pat = re.compile(b'^(\\d+):')
|
num_pat = re.compile(b'^(\\d+)[:\\-]')
|
||||||
|
|
||||||
in_result: bytes = b''
|
in_result: bytes = b''
|
||||||
hostname = socket.gethostname().encode('utf-8')
|
hostname = socket.gethostname().encode('utf-8')
|
||||||
@@ -46,6 +46,8 @@ def main() -> None:
|
|||||||
m = num_pat.match(clean_line)
|
m = num_pat.match(clean_line)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
write_hyperlink(write, in_result, line, frag=m.group(1))
|
write_hyperlink(write, in_result, line, frag=m.group(1))
|
||||||
|
else:
|
||||||
|
write(line)
|
||||||
else:
|
else:
|
||||||
if line.strip():
|
if line.strip():
|
||||||
path = quote_from_bytes(os.path.abspath(clean_line)).encode('utf-8')
|
path = quote_from_bytes(os.path.abspath(clean_line)).encode('utf-8')
|
||||||
|
|||||||
Reference in New Issue
Block a user