mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-19 14:45:29 +00:00
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
The dialog was drawn by writing newlines and relying on the terminal to wrap long lines, recording clickable ranges assuming nothing scrolled or wrapped. When the content was taller than the window, the screen scrolled and every clickable range was off by the scroll amount. Now the full layout is computed up front, with clickable ranges relative to it, and rows are drawn with absolute cursor positioning and line wrapping disabled, so the terminal never scrolls or wraps. The boxed choice layout is used only if it fits entirely, otherwise the compact one is used, and if even that does not fit, the content is bottom aligned so the choices remain visible. Choices too wide for the screen are truncated with an ellipsis. Also fix: - The hidden text placeholder not being clickable when it wraps over multiple lines, its clickable range going stale after a resize, and its range including one cell too many. - Compact choice ranges being computed by iterating over a map, putting them in random order when several choices share a line. - An empty box row or compact row being output when the first choice is wider than the screen. - truncate_at_space using a cell width as a byte offset, splitting multi-byte characters, and looping forever when a character is wider than the available width. Closes #10883
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
// License: GPLv3 Copyright: 2026, Kovid Goyal, <kovid at kovidgoyal.net>
|
|
|
|
package ask
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
func TestAskTruncateAtSpace(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
text string
|
|
width int
|
|
first, rest string
|
|
}{
|
|
{"hello world", 20, "hello world", ""},
|
|
{"hello world", 8, "hello ", "world"},
|
|
// width is in cells, the split must not be computed in bytes
|
|
{"ééééé ééééé", 8, "ééééé ", "ééééé"},
|
|
// a character wider than the available width must still be consumed
|
|
{"中文", 1, "中", "文"},
|
|
} {
|
|
first, rest := truncate_at_space(tc.text, tc.width)
|
|
if first != tc.first || rest != tc.rest {
|
|
t.Fatalf("truncate_at_space(%q, %d) = (%q, %q), expected (%q, %q)", tc.text, tc.width, first, rest, tc.first, tc.rest)
|
|
}
|
|
}
|
|
// Wrapping must always terminate and produce valid UTF-8
|
|
text := strings.Repeat("中é ", 20)
|
|
for width := 1; width < 10; width++ {
|
|
remaining := text
|
|
for i := 0; remaining != ""; i++ {
|
|
if i > len(text) {
|
|
t.Fatalf("truncate_at_space made no progress at width %d", width)
|
|
}
|
|
var line string
|
|
line, remaining = truncate_at_space(remaining, width)
|
|
if !utf8.ValidString(line) {
|
|
t.Fatalf("truncate_at_space produced invalid UTF-8 at width %d: %q", width, line)
|
|
}
|
|
}
|
|
}
|
|
}
|