Compare commits
8
Commits
v0.1.9
...
f76eccc169
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f76eccc169
|
||
|
|
801b4a2d89
|
||
|
|
d83fbc71e3 | ||
|
|
cbee630d4c
|
||
|
|
4df542f590
|
||
|
|
b406be9394 | ||
|
|
4ca4a516ae
|
||
|
|
f616651c49
|
No files matched your search
@@ -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.9`), pas la version amont de kitty embarquée dans le paquet :
|
du fork FWS (`0.1.12`), 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`
|
||||||
|
|||||||
+5
-2
@@ -31,10 +31,13 @@ Search scrollback in place :sc:`search_scrollback_prompt`
|
|||||||
|
|
||||||
The in-place search highlights every match without replacing the screen with a
|
The in-place search highlights every match without replacing the screen with a
|
||||||
pager. Prefix the query with ``\c`` to match case sensitively and with ``\r``
|
pager. Prefix the query with ``\c`` to match case sensitively and with ``\r``
|
||||||
to use a regular expression; both modifiers can be combined. While the search
|
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
|
||||||
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.
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -263,6 +263,11 @@ Detailed list of changes
|
|||||||
:kbd:`kitty_mod+H` is pressed. The panel can also be started with
|
:kbd:`kitty_mod+H` is pressed. The panel can also be started with
|
||||||
:code:`kitty +kitten help`.
|
:code:`kitty +kitten help`.
|
||||||
|
|
||||||
|
- The keyboard shortcuts panel ellipsizes a long action name inside its own
|
||||||
|
column instead of letting the edge of the dock cut it, shrinks its key column
|
||||||
|
on very narrow docks so that a row always fits, and shows the full name of
|
||||||
|
the selected action on the help line.
|
||||||
|
|
||||||
- The default :opt:`tab_title_template` now shows the abbreviated working
|
- The default :opt:`tab_title_template` now shows the abbreviated working
|
||||||
directory of the tab before its title, so the directory indicator of the tab
|
directory of the tab before its title, so the directory indicator of the tab
|
||||||
bar is visible without configuration.
|
bar is visible without configuration.
|
||||||
@@ -277,8 +282,11 @@ Detailed list of changes
|
|||||||
highlights every match without opening the pager, shows the
|
highlights every match without opening the pager, shows the
|
||||||
:code:`[current/total]` counter in the window title and moves between matches
|
:code:`[current/total]` counter in the window title and moves between matches
|
||||||
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. See
|
sensitive search and :code:`\r` for a regular expression; write a doubled
|
||||||
:doc:`basic` for the details.
|
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.
|
||||||
|
|
||||||
- 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
|
||||||
multi-key mapping available under that prefix, without waiting for a timeout.
|
multi-key mapping available under that prefix, without waiting for a timeout.
|
||||||
|
|||||||
@@ -220,28 +220,57 @@ type displayLine struct {
|
|||||||
|
|
||||||
const maxKeyDisplayWidth = 30
|
const maxKeyDisplayWidth = 30
|
||||||
|
|
||||||
|
// keyWidthFor is the number of cells reserved for the key itself. On a very
|
||||||
|
// narrow panel it shrinks, so that the action column still has room and the row
|
||||||
|
// never extends past the edge of the panel.
|
||||||
|
func keyWidthFor(panelWidth int) int {
|
||||||
|
return min(maxKeyDisplayWidth, max(panelWidth-10, 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
// keyColumnWidthFor is the number of cells the key column takes: the four space
|
||||||
|
// indent, the padded key and the separating space.
|
||||||
|
func keyColumnWidthFor(panelWidth int) int {
|
||||||
|
return 4 + keyWidthFor(panelWidth) + 1
|
||||||
|
}
|
||||||
|
|
||||||
// unmappedLabel is shown in the key column for actions with no keyboard shortcut.
|
// unmappedLabel is shown in the key column for actions with no keyboard shortcut.
|
||||||
const unmappedLabel = "(unmapped)"
|
const unmappedLabel = "(unmapped)"
|
||||||
|
|
||||||
// truncateToWidth truncates s to fit within maxWidth cells, appending "..." if
|
// ellipsis marks a truncated string. It is a single cell, so that as much of the
|
||||||
// truncated and maxWidth > 3. When maxWidth <= 3, the string is simply trimmed
|
// original text as possible is kept inside the panel.
|
||||||
// to fit without appending ellipsis (no room for it).
|
const ellipsis = "…"
|
||||||
|
|
||||||
|
// truncateToWidth truncates s to fit within maxWidth cells, appending "…" if
|
||||||
|
// truncated and maxWidth > 1. When maxWidth <= 1, the string is simply trimmed
|
||||||
|
// to fit without appending the ellipsis (no room for it).
|
||||||
func truncateToWidth(s string, maxWidth int) string {
|
func truncateToWidth(s string, maxWidth int) string {
|
||||||
if wcswidth.Stringwidth(s) <= maxWidth {
|
if wcswidth.Stringwidth(s) <= maxWidth {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
ellipsisWidth := wcswidth.Stringwidth(ellipsis)
|
||||||
runes := []rune(s)
|
runes := []rune(s)
|
||||||
if maxWidth <= 3 {
|
if maxWidth <= ellipsisWidth {
|
||||||
// Not enough room for ellipsis; just trim to fit
|
// Not enough room for the ellipsis; just trim to fit
|
||||||
for len(runes) > 0 && wcswidth.Stringwidth(string(runes)) > maxWidth {
|
for len(runes) > 0 && wcswidth.Stringwidth(string(runes)) > maxWidth {
|
||||||
runes = runes[:len(runes)-1]
|
runes = runes[:len(runes)-1]
|
||||||
}
|
}
|
||||||
return string(runes)
|
return string(runes)
|
||||||
}
|
}
|
||||||
for len(runes) > 0 && wcswidth.Stringwidth(string(runes))+3 > maxWidth {
|
for len(runes) > 0 && wcswidth.Stringwidth(string(runes))+ellipsisWidth > maxWidth {
|
||||||
runes = runes[:len(runes)-1]
|
runes = runes[:len(runes)-1]
|
||||||
}
|
}
|
||||||
return string(runes) + "..."
|
return string(runes) + ellipsis
|
||||||
|
}
|
||||||
|
|
||||||
|
// actionColumnWidth is the number of cells left for the action column of a row,
|
||||||
|
// so that a long action name is ellipsized inside the panel instead of being cut
|
||||||
|
// by its edge. The category suffix, only shown in search results, is reserved.
|
||||||
|
func (h *Handler) actionColumnWidth(width int, b *Binding) int {
|
||||||
|
used := keyColumnWidthFor(width)
|
||||||
|
if h.query != "" && h.leader == nil {
|
||||||
|
used += categorySuffixWidth(b)
|
||||||
|
}
|
||||||
|
return max(width-used, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sectionHeader returns a separator line like " ── label ─────────".
|
// sectionHeader returns a separator line like " ── label ─────────".
|
||||||
@@ -642,11 +671,22 @@ func (h *Handler) draw_screen() {
|
|||||||
h.drawFlatResults(resultsStartY, resultsHeight, width)
|
h.drawFlatResults(resultsStartY, resultsHeight, width)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw help text for selected binding
|
// Draw help text for selected binding, falling back to the full action name
|
||||||
|
// when the action column had to ellipsize it
|
||||||
h.lp.MoveCursorTo(1, helpY)
|
h.lp.MoveCursorTo(1, helpY)
|
||||||
if b := h.selectedBinding(); b != nil && b.Help != "" {
|
if b := h.selectedBinding(); b != nil {
|
||||||
helpStr := truncateToWidth(b.Help, max(width-2, 3))
|
detail := b.Help
|
||||||
h.lp.QueueWriteString(h.lp.SprintStyled("dim italic", " "+helpStr))
|
if full := h.selectedActionText(); wcswidth.Stringwidth(full) > h.actionColumnWidth(width, b) {
|
||||||
|
if detail == "" {
|
||||||
|
detail = full
|
||||||
|
} else {
|
||||||
|
detail = full + " " + detail
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if detail != "" {
|
||||||
|
helpStr := truncateToWidth(detail, max(width-2, 1))
|
||||||
|
h.lp.QueueWriteString(h.lp.SprintStyled("dim italic", " "+helpStr))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw key hints footer
|
// Draw key hints footer
|
||||||
@@ -863,8 +903,9 @@ func (h *Handler) drawBindingLine(filteredIdx, width int, isSelected bool) {
|
|||||||
b := &h.all_items[idx].binding
|
b := &h.all_items[idx].binding
|
||||||
actionDisplay := h.all_items[idx].actionText
|
actionDisplay := h.all_items[idx].actionText
|
||||||
|
|
||||||
// Build the key display
|
// Build the key display, bounded by the room the panel leaves as well
|
||||||
keyDisplay := keyDisplayText(b)
|
keyWidth := keyWidthFor(width)
|
||||||
|
keyDisplay := truncateToWidth(keyDisplayText(b), keyWidth)
|
||||||
|
|
||||||
// Determine match info for highlighting (only set when a query is active)
|
// Determine match info for highlighting (only set when a query is active)
|
||||||
var mi *matchInfo
|
var mi *matchInfo
|
||||||
@@ -893,8 +934,8 @@ func (h *Handler) drawBindingLine(filteredIdx, width int, isSelected bool) {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render key column (4-space indent + key padded to maxKeyDisplayWidth + space)
|
// Render key column (4-space indent + key padded to the key column width)
|
||||||
paddingLen := max(0, maxKeyDisplayWidth-wcswidth.Stringwidth(keyDisplay))
|
paddingLen := max(0, keyWidth-wcswidth.Stringwidth(keyDisplay))
|
||||||
pad := strings.Repeat(" ", paddingLen) + " "
|
pad := strings.Repeat(" ", paddingLen) + " "
|
||||||
ks := keyStyle
|
ks := keyStyle
|
||||||
if b.Key == "" {
|
if b.Key == "" {
|
||||||
@@ -908,7 +949,8 @@ func (h *Handler) drawBindingLine(filteredIdx, width int, isSelected bool) {
|
|||||||
h.lp.QueueWriteString(h.lp.SprintStyled(ks, " "+keyDisplay+pad))
|
h.lp.QueueWriteString(h.lp.SprintStyled(ks, " "+keyDisplay+pad))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render action display column
|
// Render action display column, bounded by the room the panel leaves
|
||||||
|
actionDisplay = truncateToWidth(actionDisplay, h.actionColumnWidth(width, b))
|
||||||
if mi != nil && len(mi.actionPositions) > 0 {
|
if mi != nil && len(mi.actionPositions) > 0 {
|
||||||
h.lp.QueueWriteString(h.highlightMatchedChars(actionDisplay, mi.actionPositions, baseStyle, matchStyle))
|
h.lp.QueueWriteString(h.highlightMatchedChars(actionDisplay, mi.actionPositions, baseStyle, matchStyle))
|
||||||
} else {
|
} else {
|
||||||
@@ -932,6 +974,19 @@ func (h *Handler) drawBindingLine(filteredIdx, width int, isSelected bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// selectedActionText returns the action text of the selected row, which is the
|
||||||
|
// full name even when the row has to ellipsize it.
|
||||||
|
func (h *Handler) selectedActionText() string {
|
||||||
|
if h.selected_idx < 0 || h.selected_idx >= len(h.filtered_idx) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
idx := h.filtered_idx[h.selected_idx]
|
||||||
|
if idx < 0 || idx >= len(h.all_items) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return h.all_items[idx].actionText
|
||||||
|
}
|
||||||
|
|
||||||
// rowToFilteredIdx converts a 0-indexed cell Y coordinate to a filtered item
|
// rowToFilteredIdx converts a 0-indexed cell Y coordinate to a filtered item
|
||||||
// index, or -1 if the cell is not over a clickable item. Internally converts
|
// index, or -1 if the cell is not over a clickable item. Internally converts
|
||||||
// to 1-indexed screen rows (matching the MoveCursorTo convention) to compare
|
// to 1-indexed screen rows (matching the MoveCursorTo convention) to compare
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kovidgoyal/kitty/tools/tui/loop"
|
"github.com/kovidgoyal/kitty/tools/tui/loop"
|
||||||
|
"github.com/kovidgoyal/kitty/tools/wcswidth"
|
||||||
)
|
)
|
||||||
|
|
||||||
// testBinding creates a Binding where Action, ActionDisplay, and Definition all
|
// testBinding creates a Binding where Action, ActionDisplay, and Definition all
|
||||||
@@ -435,13 +436,13 @@ func TestTruncateToWidth(t *testing.T) {
|
|||||||
t.Fatalf("Expected %q unchanged at exact width, got %q", "hello", got)
|
t.Fatalf("Expected %q unchanged at exact width, got %q", "hello", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Over width: truncated with ellipsis
|
// Over width: truncated with a single cell ellipsis
|
||||||
got = truncateToWidth("hello world", 8)
|
got = truncateToWidth("hello world", 8)
|
||||||
if !strings.HasSuffix(got, "...") {
|
if !strings.HasSuffix(got, ellipsis) {
|
||||||
t.Fatalf("Expected truncated string to end with '...', got %q", got)
|
t.Fatalf("Expected truncated string to end with %q, got %q", ellipsis, got)
|
||||||
}
|
}
|
||||||
if len([]rune(got)) > 8 {
|
if wcswidth.Stringwidth(got) > 8 {
|
||||||
t.Fatalf("Expected truncated string to be at most 8 runes, got %d in %q", len([]rune(got)), got)
|
t.Fatalf("Expected truncated string to be at most 8 cells, got %d in %q", wcswidth.Stringwidth(got), got)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Long key like a mouse binding should be truncated
|
// Long key like a mouse binding should be truncated
|
||||||
@@ -450,8 +451,69 @@ func TestTruncateToWidth(t *testing.T) {
|
|||||||
if len([]rune(got)) > maxKeyDisplayWidth {
|
if len([]rune(got)) > maxKeyDisplayWidth {
|
||||||
t.Fatalf("Key should be truncated to maxKeyDisplayWidth, got len=%d: %q", len([]rune(got)), got)
|
t.Fatalf("Key should be truncated to maxKeyDisplayWidth, got len=%d: %q", len([]rune(got)), got)
|
||||||
}
|
}
|
||||||
if !strings.HasSuffix(got, "...") {
|
if !strings.HasSuffix(got, ellipsis) {
|
||||||
t.Fatalf("Truncated key should end with '...', got %q", got)
|
t.Fatalf("Truncated key should end with %q, got %q", ellipsis, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestActionColumnStaysInsideThePanel(t *testing.T) {
|
||||||
|
h := newTestHandler()
|
||||||
|
b := testBinding("ctrl+shift+alt+v", "paste_from_clipboard_history", "Paste an entry from the clipboard history")
|
||||||
|
b.Category = "Copy/paste"
|
||||||
|
const width = 50
|
||||||
|
|
||||||
|
// Without a query there is no category suffix, so the whole rest of the row
|
||||||
|
// belongs to the action
|
||||||
|
keyColumnWidth := keyColumnWidthFor(width)
|
||||||
|
budget := h.actionColumnWidth(width, &b)
|
||||||
|
if budget != width-keyColumnWidth {
|
||||||
|
t.Fatalf("Expected %d cells for the action, got %d", width-keyColumnWidth, budget)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search results reserve the room the category suffix needs
|
||||||
|
h.query = "paste"
|
||||||
|
budget = h.actionColumnWidth(width, &b)
|
||||||
|
if want := width - keyColumnWidth - categorySuffixWidth(&b); budget != want {
|
||||||
|
t.Fatalf("Expected %d cells for the action next to the suffix, got %d", want, budget)
|
||||||
|
}
|
||||||
|
|
||||||
|
// A long name is ellipsized within its own column rather than cut by the edge
|
||||||
|
got := truncateToWidth(b.ActionDisplay, budget)
|
||||||
|
if w := wcswidth.Stringwidth(got); w > budget {
|
||||||
|
t.Fatalf("Action display is %d cells, over the %d cell column: %q", w, budget, got)
|
||||||
|
}
|
||||||
|
if !strings.HasSuffix(got, ellipsis) {
|
||||||
|
t.Fatalf("Expected the action display to be ellipsized, got %q", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
// A name that fits is left untouched
|
||||||
|
short := testBinding("ctrl+shift+c", "copy_to_clipboard", "Copy")
|
||||||
|
const wideWidth = 80
|
||||||
|
if got := truncateToWidth(short.ActionDisplay, h.actionColumnWidth(wideWidth, &short)); got != short.ActionDisplay {
|
||||||
|
t.Fatalf("Expected %q unchanged, got %q", short.ActionDisplay, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRowFitsInNarrowPanel(t *testing.T) {
|
||||||
|
h := newTestHandler()
|
||||||
|
h.query = "paste"
|
||||||
|
b := testBinding("ctrl+shift+alt+v press", "paste_from_clipboard_history", "Paste an entry")
|
||||||
|
b.Category = "Copy/paste"
|
||||||
|
for _, width := range []int{10, 20, 35, 50, 104} {
|
||||||
|
keyWidth := keyWidthFor(width)
|
||||||
|
key := truncateToWidth(keyDisplayText(&b), keyWidth)
|
||||||
|
action := truncateToWidth(b.ActionDisplay, h.actionColumnWidth(width, &b))
|
||||||
|
row := 4 + wcswidth.Stringwidth(key) + max(0, keyWidth-wcswidth.Stringwidth(key)) + 1 + wcswidth.Stringwidth(action)
|
||||||
|
if row > width {
|
||||||
|
t.Fatalf("Row is %d cells wide in a %d cell panel: key %q action %q", row, width, key, action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The key column only shrinks when the panel cannot hold the full one
|
||||||
|
if keyWidthFor(104) != maxKeyDisplayWidth {
|
||||||
|
t.Fatalf("Expected the full key column on a wide panel, got %d", keyWidthFor(104))
|
||||||
|
}
|
||||||
|
if keyWidthFor(20) >= maxKeyDisplayWidth {
|
||||||
|
t.Fatalf("Expected the key column to shrink on a narrow panel, got %d", keyWidthFor(20))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.9\x1b[39m by \x1b[1;34mBlackAngelTV\x1b[22;39m\n");
|
printf("\x1b[3mfws-kitty\x1b[23m \x1b[32m0.1.12\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.9 by BlackAngelTV\n");
|
printf("fws-kitty 0.1.12 by BlackAngelTV\n");
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-1
@@ -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 = {}
|
||||||
|
|||||||
@@ -6,17 +6,24 @@
|
|||||||
The query parser and the matcher live here, away from the screen code, so that
|
The query parser and the matcher live here, away from the screen code, so that
|
||||||
they can be tested without a running terminal. A query can start with two
|
they can be tested without a running terminal. A query can start with two
|
||||||
modifiers, in any order: ``\\c`` makes matching case sensitive and ``\\r``
|
modifiers, in any order: ``\\c`` makes matching case sensitive and ``\\r``
|
||||||
treats the query as a regular expression.
|
treats the query as a regular expression. A doubled backslash escapes the
|
||||||
|
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
|
||||||
@@ -51,12 +58,36 @@ 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()
|
||||||
case_sensitive = is_regex = False
|
case_sensitive = is_regex = False
|
||||||
while len(text) > 1 and text[0] == '\\':
|
while len(text) > 1 and text[0] == '\\':
|
||||||
modifier = text[1].lower()
|
modifier = text[1].lower()
|
||||||
|
if modifier == '\\':
|
||||||
|
# A doubled backslash stands for a literal one and ends the modifier
|
||||||
|
# section, which is the only way to search for \c or \r themselves.
|
||||||
|
text = text[1:]
|
||||||
|
break
|
||||||
if modifier == CASE_SENSITIVE_MODIFIER:
|
if modifier == CASE_SENSITIVE_MODIFIER:
|
||||||
case_sensitive = True
|
case_sensitive = True
|
||||||
elif modifier == REGEX_MODIFIER:
|
elif modifier == REGEX_MODIFIER:
|
||||||
|
|||||||
+23
-6
@@ -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
|
||||||
@@ -2676,8 +2677,10 @@ class Window:
|
|||||||
'sc',
|
'sc',
|
||||||
"""
|
"""
|
||||||
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. Matches are navigated with n and N and
|
sensitive search and with \\r for a regular expression. To search for those two strings literally,
|
||||||
the search ends with Escape. The [current/total] counter is shown in the window title.
|
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 and the
|
||||||
|
current match uses the second mark color.
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
def search_scrollback_prompt(self) -> bool | None:
|
def search_scrollback_prompt(self) -> bool | None:
|
||||||
@@ -2691,7 +2694,10 @@ class Window:
|
|||||||
self.clear_scrollback_search()
|
self.clear_scrollback_search()
|
||||||
|
|
||||||
get_boss().get_line(
|
get_boss().get_line(
|
||||||
_('Search the scrollback. Prefix the query with \\c for a case sensitive search and \\r for a regular expression.'),
|
_(
|
||||||
|
'Search the scrollback. Prefix the query with \\c for a case sensitive search and \\r for a regular expression.'
|
||||||
|
' Write a double backslash to search for those strings literally.'
|
||||||
|
),
|
||||||
done,
|
done,
|
||||||
window=self,
|
window=self,
|
||||||
prompt=_('search> '),
|
prompt=_('search> '),
|
||||||
@@ -2724,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)
|
||||||
|
|
||||||
@@ -2738,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
|
||||||
@@ -2781,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
|
||||||
|
|||||||
@@ -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,
|
||||||
@@ -46,6 +49,25 @@ class TestScrollbackSearch(BaseTest):
|
|||||||
with self.assertRaises(InvalidQuery):
|
with self.assertRaises(InvalidQuery):
|
||||||
compile_query(parse_query('\\r ('))
|
compile_query(parse_query('\\r ('))
|
||||||
|
|
||||||
|
def test_parse_query_escaped_backslash(self):
|
||||||
|
# A doubled backslash searches text starting with a backslash instead of
|
||||||
|
# being read as a modifier, so both modifier prefixes remain reachable.
|
||||||
|
for raw, expected in (('\\\\c', '\\c'), ('\\\\r', '\\r'), ('\\\\C', '\\C'), ('\\\\', '\\')):
|
||||||
|
with self.subTest(raw=raw):
|
||||||
|
q = parse_query(raw)
|
||||||
|
self.ae((q.text, q.case_sensitive, q.is_regex), (expected, False, False))
|
||||||
|
|
||||||
|
# Modifiers still combine with an escaped prefix in the searched text
|
||||||
|
q = parse_query('\\c\\\\r')
|
||||||
|
self.ae((q.text, q.case_sensitive, q.is_regex), ('\\r', True, False))
|
||||||
|
|
||||||
|
# The escaped prefix is matched like any other text, case insensitively
|
||||||
|
# by default, and the case sensitive modifier still applies to it.
|
||||||
|
matches = find_matches(['a \\c b', 'a \\C b'], parse_query('\\\\c'))
|
||||||
|
self.ae([(m.line, m.start, m.end) for m in matches], [(0, 2, 4), (1, 2, 4)])
|
||||||
|
matches = find_matches(['a \\c b', 'a \\C b'], parse_query('\\c\\\\c'))
|
||||||
|
self.ae([(m.line, m.start, m.end) for m in matches], [(0, 2, 4)])
|
||||||
|
|
||||||
def test_find_matches_plain(self):
|
def test_find_matches_plain(self):
|
||||||
lines = ['needle at start', 'Needle again', 'nothing', 'a needle here']
|
lines = ['needle at start', 'Needle again', 'nothing', 'a needle here']
|
||||||
matches = find_matches(lines, parse_query('needle'))
|
matches = find_matches(lines, parse_query('needle'))
|
||||||
@@ -64,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
@@ -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.9
|
pkgver=0.1.12
|
||||||
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
@@ -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.9"), "by", formatter.Title("BlackAngelTV"))
|
fmt.Sprintln(formatter.Italic("fws-kitty"), formatter.Opt("0.1.12"), "by", formatter.Title("BlackAngelTV"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Command) ShowVersion() {
|
func (self *Command) ShowVersion() {
|
||||||
|
|||||||
Reference in new issue
Block a user