Tiny windows: forms no longer crash, and wide falls back to compact

A form given a negative height panicked (Backups, Alerts, Move, Server
in a small window), and a forced wide layout overflowed below 60x17.
TestTinyWindows opens every screen at small sizes in all layouts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vvvomitandClaude Opus 5.5 committed 2026-10-29 15:53:22 +03:30
1 parent f0f838f106
commit 75a8724be0
3 files changed
+39

No files matched your search

+1
View File
@@ -308,6 +308,7 @@ const maxFormWidth = 96
// View renders the form inside height lines, scrolled so the focused field stays visible.
func (f *form) View(width, height int) string {
width = min(width, maxFormWidth)
height = max(height, 3) // callers pass what's left, which a tiny window makes negative
f.width = width
var lines []string
focusStart, focusEnd := 0, 0
+3
View File
@@ -58,6 +58,9 @@ func (a *App) cycleLayout() {
}
func (a *App) compact() bool {
if a.w > 0 && (a.w < 60 || a.h < 17) {
return true // the wide layout's menu and panels don't fit, whatever was picked
}
switch a.layout {
case "compact":
return true
+35
View File
@@ -309,3 +309,38 @@ func TestSidebarFits(t *testing.T) {
t.Errorf("%d lines, the first %q:\n%s", len(lines), lines[0], strings.Join(lines, "\n"))
}
}
// Every screen draws in tiny windows without crashing or growing taller
// than the window.
func TestTinyWindows(t *testing.T) {
for _, sz := range [][2]int{{20, 6}, {30, 10}, {40, 15}, {60, 12}, {80, 24}, {120, 36}, {70, 50}} {
for _, layout := range []string{"auto", "compact", "wide"} {
a := demoApp(t, sz[0], sz[1])
a.layout = layout
for i := range a.screens {
if a.screens[i].name() == "Deploy" {
continue
}
a.step = i
a.cur().enter(a.cfg)
func() {
defer func() {
if r := recover(); r != nil {
t.Errorf("%s at %dx%d (%s): %v", a.screens[i].name(), sz[0], sz[1], layout, r)
}
}()
lines := strings.Split(a.View(), "\n")
if len(lines) > sz[1] {
t.Errorf("%s at %dx%d (%s) is %d lines tall", a.screens[i].name(), sz[0], sz[1], layout, len(lines))
}
for _, l := range lines {
if w := ansi.StringWidth(l); w > sz[0] {
t.Errorf("%s at %dx%d (%s) has a line %d wide: %q", a.screens[i].name(), sz[0], sz[1], layout, w, ansi.Strip(l))
break
}
}
}()
}
}
}
}