diff --git a/internal/ui/form.go b/internal/ui/form.go index 47d0293..19c98b2 100644 --- a/internal/ui/form.go +++ b/internal/ui/form.go @@ -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 diff --git a/internal/ui/layout.go b/internal/ui/layout.go index d62a15c..0a8c799 100644 --- a/internal/ui/layout.go +++ b/internal/ui/layout.go @@ -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 diff --git a/internal/ui/layout_test.go b/internal/ui/layout_test.go index 5788fe1..141b647 100644 --- a/internal/ui/layout_test.go +++ b/internal/ui/layout_test.go @@ -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 + } + } + }() + } + } + } +}