fix(display): clip the header line to the terminal width like every other row

The "[+] op N/M" header was the one line bypassing renderSegs, so on a
very narrow terminal it could wrap and desync the cursor arithmetic the
rest of the design guarantees against. Route it through the same clip
and cover degenerate widths (8, 12 cells) in the invariant test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2026-08-15 17:51:38 +02:00 • committed by Guillaume Lours
parent 9fc38cce0e
commit 136763181b
2 changed files with 5 additions and 2 deletions

View file

@ -65,7 +65,8 @@ const (
// layoutFrame renders the whole progress block, one string per terminal row.
func layoutFrame(t *taskTree, operation string, o layoutOpts) []string {
done, total := t.counts()
lines := []string{fmt.Sprintf("[+] %s %d/%d", operation, done, total)}
header := fmt.Sprintf("[+] %s %d/%d", operation, done, total)
lines := []string{renderSegs([]seg{{text: header}}, o.width)}
rows := buildRows(t, o)
maxRows := max(o.height-2, 1)

View file

@ -116,7 +116,9 @@ func adversarialEvents() []api.Resource {
}
func TestTerm_NoLineEverExceedsTerminalWidth(t *testing.T) {
for _, width := range []int{20, 30, 40, 60, 80, 120} {
// 8 and 12 exercise the degenerate widths where even the "[+] op N/M"
// header must be clipped rather than allowed to wrap
for _, width := range []int{8, 12, 20, 30, 40, 60, 80, 120} {
t.Run(fmt.Sprintf("width=%d", width), func(t *testing.T) {
w, buf, _ := newTermWriter(width, 40)
feed(w, adversarialEvents()...)