Merge pull request 'feat(search): highlight the current match in its own color' (#53) from feat/search-current-match into main
Release / release (push) Canceled after 0s
CI / check (push) Failing after 5m5s

This commit was merged in pull request #53.
This commit is contained in:
BlackAngelTV committed 2026-12-03 10:06:07 +01:00
commit d83fbc71e3
11 files changed
+97 -12

No files matched your search

+1 -1
View File
@@ -302,7 +302,7 @@ _branch=feat/file-manager-panel
### Publication automatique ### Publication automatique
`version`, à la racine, est la source de vérité des releases. Il suit la version `version`, à la racine, est la source de vérité des releases. Il suit la version
du fork FWS (`0.1.10`), pas la version amont de kitty embarquée dans le paquet : du fork FWS (`0.1.11`), pas la version amont de kitty embarquée dans le paquet :
c'est elle qui nomme le tag, la release et le paquet c'est elle qui nomme le tag, la release et le paquet
`fws-kitty-<version>-<rel>`. Il doit rester égal à `pkgver` dans `fws-kitty-<version>-<rel>`. Il doit rester égal à `pkgver` dans
`packaging/PKGBUILD` et à la version affichée par `fws-kitty` `packaging/PKGBUILD` et à la version affichée par `fws-kitty`
+3 -1
View File
@@ -35,7 +35,9 @@ to use a regular expression; both modifiers can be combined. Write a doubled
backslash (``\\c``, ``\\r``) to search for those prefixes literally. While the search backslash (``\\c``, ``\\r``) to search for those prefixes literally. While the search
is active, :kbd:`n` jumps to the next match, :kbd:`N` to the previous one and is active, :kbd:`n` jumps to the next match, :kbd:`N` to the previous one and
:kbd:`Escape` ends it. The ``[current/total]`` counter is shown in the window :kbd:`Escape` ends it. The ``[current/total]`` counter is shown in the window
title and matches use the first marker color (see :opt:`mark1_foreground`). title, matches use the first mark color (see :opt:`mark1_foreground`) and the
current match uses the second one (:opt:`mark2_foreground`), so it stands out
from the other matches.
The :ac:`scrollback_search_next`, :ac:`scrollback_search_prev` and The :ac:`scrollback_search_next`, :ac:`scrollback_search_prev` and
:ac:`clear_scrollback_search` actions can also be mapped directly. :ac:`clear_scrollback_search` actions can also be mapped directly.
+2
View File
@@ -279,6 +279,8 @@ Detailed list of changes
with :kbd:`n` and :kbd:`N`. Prefix the query with :code:`\c` for a case with :kbd:`n` and :kbd:`N`. Prefix the query with :code:`\c` for a case
sensitive search and :code:`\r` for a regular expression; write a doubled sensitive search and :code:`\r` for a regular expression; write a doubled
backslash (:code:`\\c`, :code:`\\r`) to search for those prefixes literally. backslash (:code:`\\c`, :code:`\\r`) to search for those prefixes literally.
The current match is drawn with the second mark color, so the match reached
with :kbd:`n` and :kbd:`N` is visible without looking at the window title.
See :doc:`basic` for the details. See :doc:`basic` for the details.
- A configurable :opt:`leader` key now opens a which-key panel listing every - A configurable :opt:`leader` key now opens a which-key panel listing every
+2 -2
View File
@@ -424,10 +424,10 @@ handle_fast_commandline(CLISpec *cli_spec, const char *instance_group_prefix) {
if (get_bool_cli_val(cli_spec, "version")) { if (get_bool_cli_val(cli_spec, "version")) {
if (isatty(STDOUT_FILENO)) { if (isatty(STDOUT_FILENO)) {
printf("\x1b[3mkitty\x1b[23m \x1b[32m%s\x1b[39m created by \x1b[1;34mKovid Goyal\x1b[22;39m\n", KITTY_VERSION); printf("\x1b[3mkitty\x1b[23m \x1b[32m%s\x1b[39m created by \x1b[1;34mKovid Goyal\x1b[22;39m\n", KITTY_VERSION);
printf("\x1b[3mfws-kitty\x1b[23m \x1b[32m0.1.10\x1b[39m by \x1b[1;34mBlackAngelTV\x1b[22;39m\n"); printf("\x1b[3mfws-kitty\x1b[23m \x1b[32m0.1.11\x1b[39m by \x1b[1;34mBlackAngelTV\x1b[22;39m\n");
} else { } else {
printf("kitty %s created by Kovid Goyal\n", KITTY_VERSION); printf("kitty %s created by Kovid Goyal\n", KITTY_VERSION);
printf("fws-kitty 0.1.10 by BlackAngelTV\n"); printf("fws-kitty 0.1.11 by BlackAngelTV\n");
} }
exit(0); exit(0);
} }
+19 -1
View File
@@ -2,7 +2,7 @@
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
import re import re
from collections.abc import Callable, Generator, Iterable, Sequence from collections.abc import Callable, Generator, Iterable, Mapping, Sequence
from re import Pattern from re import Pattern
from typing import Union from typing import Union
@@ -29,6 +29,24 @@ def marker_from_regex(expression: Union[str, 'Pattern[str]'], color: int, flags:
return marker return marker
def marker_from_spans(spans: Mapping[str, Sequence[tuple[int, int, int]]]) -> MarkerFunc:
"""A marker built from pre-computed spans, keyed by the text of their line.
Each span is (start, end, color), where color is a mark number. Marker
functions receive one line at a time without its number, hence the lookup
by text.
"""
def marker(text: str, left_address: int, right_address: int, color_address: int) -> Generator[None, None, None]:
for start, end, color in spans.get(text, ()):
set_uint_at_address(left_address, start)
set_uint_at_address(right_address, end - 1)
set_uint_at_address(color_address, max(1, min(color, 3)))
yield
return marker
def marker_from_multiple_regex(regexes: Iterable[tuple[int, str]], flags: int = re.UNICODE) -> MarkerFunc: def marker_from_multiple_regex(regexes: Iterable[tuple[int, str]], flags: int = re.UNICODE) -> MarkerFunc:
expr = '' expr = ''
color_map = {} color_map = {}
+25
View File
@@ -13,11 +13,17 @@ modifier syntax, so that the two prefixes can be searched for literally.
from __future__ import annotations from __future__ import annotations
import re import re
from collections.abc import Sequence
from dataclasses import dataclass, field from dataclasses import dataclass, field
CASE_SENSITIVE_MODIFIER = 'c' CASE_SENSITIVE_MODIFIER = 'c'
REGEX_MODIFIER = 'r' REGEX_MODIFIER = 'r'
# Mark numbers (see :opt:`mark1_background`) used to highlight the matches. The
# current match gets its own color so that it stands out from the other ones.
MATCH_COLOR = 1
CURRENT_MATCH_COLOR = 2
class InvalidQuery(ValueError): class InvalidQuery(ValueError):
pass pass
@@ -52,6 +58,25 @@ class ScrollbackSearch:
def __len__(self) -> int: def __len__(self) -> int:
return len(self.matches) return len(self.matches)
@property
def current_match(self) -> Match | None:
return self.matches[self.index] if self.matches else None
def marker_spans(self, lines: Sequence[str]) -> dict[str, tuple[tuple[int, int, int], ...]]:
"""Spans to highlight, keyed by the text of the line holding them.
Marker functions are called once per line with only its text, never with
its number, so the spans are grouped by line text. Lines that are
identical to the current one are therefore highlighted alike, which the
user cannot tell apart since their text is the same.
"""
current = self.current_match
spans: dict[str, list[tuple[int, int, int]]] = {}
for match in self.matches:
color = CURRENT_MATCH_COLOR if match == current else MATCH_COLOR
spans.setdefault(lines[match.line], []).append((match.start, match.end, color))
return {text: tuple(found) for text, found in spans.items()}
def parse_query(raw: str) -> Query: def parse_query(raw: str) -> Query:
text = (raw or '').strip() text = (raw or '').strip()
+17 -4
View File
@@ -827,6 +827,7 @@ class Window:
self.actions_on_removal: list[Callable[['Window'], None]] = [] self.actions_on_removal: list[Callable[['Window'], None]] = []
self.current_marker_spec: tuple[str, str | tuple[tuple[int, str], ...]] | None = None self.current_marker_spec: tuple[str, str | tuple[tuple[int, str], ...]] | None = None
self.scrollback_search: ScrollbackSearch | None = None self.scrollback_search: ScrollbackSearch | None = None
self.scrollback_search_spans: dict[str, tuple[tuple[int, int, int], ...]] = {}
self.scrollback_search_mode: str = '' self.scrollback_search_mode: str = ''
self.scrollback_search_saved_marker: tuple[str, str | tuple[tuple[int, str], ...]] | None = None self.scrollback_search_saved_marker: tuple[str, str | tuple[tuple[int, str], ...]] | None = None
self.scrollback_search_saved_title: str | None = None self.scrollback_search_saved_title: str | None = None
@@ -2678,7 +2679,8 @@ class Window:
Search the scrollback in place, highlighting every match. Prefix the query with \\c for a case Search the scrollback in place, highlighting every match. Prefix the query with \\c for a case
sensitive search and with \\r for a regular expression. To search for those two strings literally, sensitive search and with \\r for a regular expression. To search for those two strings literally,
write a double backslash instead (``\\\\c`` and ``\\\\r``). Matches are navigated with n and N and write a double backslash instead (``\\\\c`` and ``\\\\r``). Matches are navigated with n and N and
the search ends with Escape. The [current/total] counter is shown in the window title. the search ends with Escape. The [current/total] counter is shown in the window title and the
current match uses the second mark color.
""", """,
) )
def search_scrollback_prompt(self) -> bool | None: def search_scrollback_prompt(self) -> bool | None:
@@ -2728,12 +2730,12 @@ class Window:
ring_bell(self.os_window_id) ring_bell(self.os_window_id)
return return
self.clear_scrollback_search() self.clear_scrollback_search()
from .marks import marker_from_regex
self.scrollback_search = ScrollbackSearch(query, pattern, matches, total_lines=len(lines)) search = ScrollbackSearch(query, pattern, matches, total_lines=len(lines))
self.scrollback_search = search
self.scrollback_search_spans = search.marker_spans(lines)
self.scrollback_search_saved_marker = self.current_marker_spec self.scrollback_search_saved_marker = self.current_marker_spec
self.scrollback_search_saved_title = self.override_title self.scrollback_search_saved_title = self.override_title
self.screen.set_marker(marker_from_regex(pattern, 1))
self._push_scrollback_search_mode() self._push_scrollback_search_mode()
self._goto_scrollback_match(0) self._goto_scrollback_match(0)
@@ -2742,6 +2744,7 @@ class Window:
if self.scrollback_search is None: if self.scrollback_search is None:
return return
self.scrollback_search = None self.scrollback_search = None
self.scrollback_search_spans = {}
self.screen.set_marker() self.screen.set_marker()
self.current_marker_spec = None self.current_marker_spec = None
saved = self.scrollback_search_saved_marker saved = self.scrollback_search_saved_marker
@@ -2785,8 +2788,18 @@ class Window:
search.index = index % len(search.matches) search.index = index % len(search.matches)
match = search.matches[search.index] match = search.matches[search.index]
self.set_title(f'[{search.index + 1}/{len(search.matches)}] {search.query.text}') self.set_title(f'[{search.index + 1}/{len(search.matches)}] {search.query.text}')
self._refresh_scrollback_search_marker()
self.screen.scroll_to_absolute(scroll_offset_for(match, search.total_lines, self.screen.lines)) self.screen.scroll_to_absolute(scroll_offset_for(match, search.total_lines, self.screen.lines))
def _refresh_scrollback_search_marker(self) -> None:
from .marks import marker_from_spans
# Clear first, as set_marker() only releases the previous callable when
# it is called without one. Marking every line again is needed anyway to
# recolor the match that was current until now.
self.screen.set_marker()
self.screen.set_marker(marker_from_spans(self.scrollback_search_spans))
def _push_scrollback_search_mode(self) -> None: def _push_scrollback_search_mode(self) -> None:
from .fast_data_types import GLFW_FKEY_ESCAPE, GLFW_MOD_SHIFT from .fast_data_types import GLFW_FKEY_ESCAPE, GLFW_MOD_SHIFT
from .options.utils import KeyboardMode, KeyDefinition, SingleKey from .options.utils import KeyboardMode, KeyDefinition, SingleKey
+25
View File
@@ -5,8 +5,11 @@ import re
import time import time
from kitty.scrollback_search import ( from kitty.scrollback_search import (
CURRENT_MATCH_COLOR,
MATCH_COLOR,
InvalidQuery, InvalidQuery,
Match, Match,
ScrollbackSearch,
compile_query, compile_query,
find_matches, find_matches,
parse_query, parse_query,
@@ -83,6 +86,28 @@ class TestScrollbackSearch(BaseTest):
# Empty matches are skipped and do not loop forever # Empty matches are skipped and do not loop forever
self.ae(find_matches(['abc'], parse_query('\\r x*')), []) self.ae(find_matches(['abc'], parse_query('\\r x*')), [])
def test_current_match(self):
lines = ['one 17 here', 'nothing', '17 and 17']
query = parse_query('17')
matches = find_matches(lines, query)
search = ScrollbackSearch(query, compile_query(query), matches, total_lines=len(lines))
self.ae(len(search), 3)
self.ae(search.current_match, Match(0, 4, 6))
search.index = 2
self.ae(search.current_match, Match(2, 7, 9))
# The current match is the only one with its own color, and navigation
# moves that color along
spans = search.marker_spans(lines)
self.ae(spans['one 17 here'], ((4, 6, MATCH_COLOR),))
self.ae(spans['17 and 17'], ((0, 2, MATCH_COLOR), (7, 9, CURRENT_MATCH_COLOR)))
search.index = 1
self.ae(search.marker_spans(lines)['17 and 17'], ((0, 2, CURRENT_MATCH_COLOR), (7, 9, MATCH_COLOR)))
# Wrapping the index keeps exactly one current match selected
search.index = 4 % len(search.matches)
self.ae(sum(1 for found in search.marker_spans(lines).values() for span in found if span[2] == CURRENT_MATCH_COLOR), 1)
def test_scroll_offset(self): def test_scroll_offset(self):
self.ae(scroll_offset_for(Match(0, 0, 1), 100, 10), 90) self.ae(scroll_offset_for(Match(0, 0, 1), 100, 10), 90)
self.ae(scroll_offset_for(Match(50, 0, 1), 100, 10), 43) self.ae(scroll_offset_for(Match(50, 0, 1), 100, 10), 43)
+1 -1
View File
@@ -13,7 +13,7 @@
pkgname=fws-kitty pkgname=fws-kitty
# Fork version from the version file: it names the release and the package. # Fork version from the version file: it names the release and the package.
# The upstream kitty release built inside is tracked by _kittyver below. # The upstream kitty release built inside is tracked by _kittyver below.
pkgver=0.1.10 pkgver=0.1.11
pkgrel=1 pkgrel=1
pkgdesc='Fast, feature-rich, GPU based terminal (FWS fork with the file-manager kitten)' pkgdesc='Fast, feature-rich, GPU based terminal (FWS fork with the file-manager kitten)'
arch=('x86_64' 'aarch64') arch=('x86_64' 'aarch64')
+1 -1
View File
@@ -31,7 +31,7 @@ func ShowError(err error) {
func (self *Command) version_string(formatter *markup.Context) string { func (self *Command) version_string(formatter *markup.Context) string {
return fmt.Sprintln(formatter.Italic(self.CommandStringForUsage()), formatter.Opt(kitty.VersionString+kitty.VersionSuffix), "created by", formatter.Title("Kovid Goyal")) + return fmt.Sprintln(formatter.Italic(self.CommandStringForUsage()), formatter.Opt(kitty.VersionString+kitty.VersionSuffix), "created by", formatter.Title("Kovid Goyal")) +
fmt.Sprintln(formatter.Italic("fws-kitty"), formatter.Opt("0.1.10"), "by", formatter.Title("BlackAngelTV")) fmt.Sprintln(formatter.Italic("fws-kitty"), formatter.Opt("0.1.11"), "by", formatter.Title("BlackAngelTV"))
} }
func (self *Command) ShowVersion() { func (self *Command) ShowVersion() {
+1 -1
View File
@@ -1 +1 @@
0.1.10 0.1.11