From 801b4a2d89806f64f88ea9241b0c3c1d6f45a6a4 Mon Sep 17 00:00:00 2001 From: BlackAngelTVdev Date: Thu, 3 Dec 2026 10:16:57 +0100 Subject: [PATCH 1/2] fix(help): keep the shortcuts panel inside its dock The action column of the panel was written with no width limit, so on a narrow dock a long action name was cut by the edge of the panel in the middle of an identifier, and a selected row padded with reverse video overflowed. The column is now bounded by the room the row leaves and ellipsized with a single cell ellipsis, the key column shrinks on very narrow docks, and the full name of the selected action stays reachable on the help line. Fixes #50 --- docs/changelog.rst | 5 ++ kittens/command_palette/main.go | 87 +++++++++++++++++++++++----- kittens/command_palette/main_test.go | 76 +++++++++++++++++++++--- 3 files changed, 145 insertions(+), 23 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 77bd55a..be989d1 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -263,6 +263,11 @@ Detailed list of changes :kbd:`kitty_mod+H` is pressed. The panel can also be started with :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 directory of the tab before its title, so the directory indicator of the tab bar is visible without configuration. diff --git a/kittens/command_palette/main.go b/kittens/command_palette/main.go index d90be82..72d9aae 100644 --- a/kittens/command_palette/main.go +++ b/kittens/command_palette/main.go @@ -220,28 +220,57 @@ type displayLine struct { 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. const unmappedLabel = "(unmapped)" -// truncateToWidth truncates s to fit within maxWidth cells, appending "..." if -// truncated and maxWidth > 3. When maxWidth <= 3, the string is simply trimmed -// to fit without appending ellipsis (no room for it). +// ellipsis marks a truncated string. It is a single cell, so that as much of the +// original text as possible is kept inside the panel. +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 { if wcswidth.Stringwidth(s) <= maxWidth { return s } + ellipsisWidth := wcswidth.Stringwidth(ellipsis) runes := []rune(s) - if maxWidth <= 3 { - // Not enough room for ellipsis; just trim to fit + if maxWidth <= ellipsisWidth { + // Not enough room for the ellipsis; just trim to fit for len(runes) > 0 && wcswidth.Stringwidth(string(runes)) > maxWidth { runes = runes[:len(runes)-1] } 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] } - 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 ─────────". @@ -642,11 +671,22 @@ func (h *Handler) draw_screen() { 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) - if b := h.selectedBinding(); b != nil && b.Help != "" { - helpStr := truncateToWidth(b.Help, max(width-2, 3)) - h.lp.QueueWriteString(h.lp.SprintStyled("dim italic", " "+helpStr)) + if b := h.selectedBinding(); b != nil { + detail := b.Help + 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 @@ -863,8 +903,9 @@ func (h *Handler) drawBindingLine(filteredIdx, width int, isSelected bool) { b := &h.all_items[idx].binding actionDisplay := h.all_items[idx].actionText - // Build the key display - keyDisplay := keyDisplayText(b) + // Build the key display, bounded by the room the panel leaves as well + keyWidth := keyWidthFor(width) + keyDisplay := truncateToWidth(keyDisplayText(b), keyWidth) // Determine match info for highlighting (only set when a query is active) var mi *matchInfo @@ -893,8 +934,8 @@ func (h *Handler) drawBindingLine(filteredIdx, width int, isSelected bool) { return s } - // Render key column (4-space indent + key padded to maxKeyDisplayWidth + space) - paddingLen := max(0, maxKeyDisplayWidth-wcswidth.Stringwidth(keyDisplay)) + // Render key column (4-space indent + key padded to the key column width) + paddingLen := max(0, keyWidth-wcswidth.Stringwidth(keyDisplay)) pad := strings.Repeat(" ", paddingLen) + " " ks := keyStyle 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)) } - // 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 { h.lp.QueueWriteString(h.highlightMatchedChars(actionDisplay, mi.actionPositions, baseStyle, matchStyle)) } 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 // 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 diff --git a/kittens/command_palette/main_test.go b/kittens/command_palette/main_test.go index 2197d4d..74815af 100644 --- a/kittens/command_palette/main_test.go +++ b/kittens/command_palette/main_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/kovidgoyal/kitty/tools/tui/loop" + "github.com/kovidgoyal/kitty/tools/wcswidth" ) // 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) } - // Over width: truncated with ellipsis + // Over width: truncated with a single cell ellipsis got = truncateToWidth("hello world", 8) - if !strings.HasSuffix(got, "...") { - t.Fatalf("Expected truncated string to end with '...', got %q", got) + if !strings.HasSuffix(got, ellipsis) { + t.Fatalf("Expected truncated string to end with %q, got %q", ellipsis, got) } - if len([]rune(got)) > 8 { - t.Fatalf("Expected truncated string to be at most 8 runes, got %d in %q", len([]rune(got)), got) + if wcswidth.Stringwidth(got) > 8 { + 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 @@ -450,8 +451,69 @@ func TestTruncateToWidth(t *testing.T) { if len([]rune(got)) > maxKeyDisplayWidth { t.Fatalf("Key should be truncated to maxKeyDisplayWidth, got len=%d: %q", len([]rune(got)), got) } - if !strings.HasSuffix(got, "...") { - t.Fatalf("Truncated key should end with '...', got %q", got) + if !strings.HasSuffix(got, ellipsis) { + 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)) } } From f76eccc1697a834dd296ff46ccb50857d2014356 Mon Sep 17 00:00:00 2001 From: BlackAngelTVdev Date: Thu, 3 Dec 2026 10:16:57 +0100 Subject: [PATCH 2/2] chore(release): bump the fork version to 0.1.12 The shortcuts panel now renders differently, so cut a patch release. All the version copies must agree for the packaging workflow. --- README.md | 2 +- kitty/launcher/main.c | 4 ++-- packaging/PKGBUILD | 2 +- tools/cli/help.go | 2 +- version | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 71fb78c..75dd4e5 100644 --- a/README.md +++ b/README.md @@ -302,7 +302,7 @@ _branch=feat/file-manager-panel ### Publication automatique `version`, à la racine, est la source de vérité des releases. Il suit la version -du fork FWS (`0.1.11`), 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 `fws-kitty--`. Il doit rester égal à `pkgver` dans `packaging/PKGBUILD` et à la version affichée par `fws-kitty` diff --git a/kitty/launcher/main.c b/kitty/launcher/main.c index 4c2e600..4343a0b 100644 --- a/kitty/launcher/main.c +++ b/kitty/launcher/main.c @@ -424,10 +424,10 @@ handle_fast_commandline(CLISpec *cli_spec, const char *instance_group_prefix) { if (get_bool_cli_val(cli_spec, "version")) { 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[3mfws-kitty\x1b[23m \x1b[32m0.1.11\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 { printf("kitty %s created by Kovid Goyal\n", KITTY_VERSION); - printf("fws-kitty 0.1.11 by BlackAngelTV\n"); + printf("fws-kitty 0.1.12 by BlackAngelTV\n"); } exit(0); } diff --git a/packaging/PKGBUILD b/packaging/PKGBUILD index b089096..134705f 100644 --- a/packaging/PKGBUILD +++ b/packaging/PKGBUILD @@ -13,7 +13,7 @@ pkgname=fws-kitty # Fork version from the version file: it names the release and the package. # The upstream kitty release built inside is tracked by _kittyver below. -pkgver=0.1.11 +pkgver=0.1.12 pkgrel=1 pkgdesc='Fast, feature-rich, GPU based terminal (FWS fork with the file-manager kitten)' arch=('x86_64' 'aarch64') diff --git a/tools/cli/help.go b/tools/cli/help.go index d5080ea..de9829a 100644 --- a/tools/cli/help.go +++ b/tools/cli/help.go @@ -31,7 +31,7 @@ func ShowError(err error) { 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")) + - fmt.Sprintln(formatter.Italic("fws-kitty"), formatter.Opt("0.1.11"), "by", formatter.Title("BlackAngelTV")) + fmt.Sprintln(formatter.Italic("fws-kitty"), formatter.Opt("0.1.12"), "by", formatter.Title("BlackAngelTV")) } func (self *Command) ShowVersion() { diff --git a/version b/version index 20f4951..0e24a92 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.1.11 +0.1.12