fix(tea): fall back to 80x24 when initial GetSize returns 0 (blank first frame under tmux)#1718
Conversation
Program.Run reads the terminal size once at startup via term.GetSize and trusts the result, checking only the error. Some terminals — tmux is the common case, before the pty size is negotiated — return (0, 0) with no error. Run then resizes the renderer to 0x0 and the event loop, which only paints after a message, renders the first frame into a 0x0 viewport: the whole screen is blank until a real SIGWINCH (a resize or keypress) arrives. This looks like the program hung, and it happens regardless of the model's View() — even a width-agnostic view renders blank because the renderer viewport is 0. Fall back to a standard 80x24 for any zero dimension so the first frame paints; the genuine size still arrives via WindowSizeMsg a moment later and re-renders correctly. Adds fallbackZeroSize + a unit test.
|
Gentle ping on this one 🙂 It's a small (+52/-1), self-contained fix with a unit test for a real tmux issue: Happy to adjust the fallback dimensions or take a different approach if you'd prefer. Thanks for taking a look when you get a chance! |
|
Hi! Just a friendly ping on this PR. It's been open for a while — would appreciate a review when you get a chance. Thanks for your time! |
Problem
Launching a Bubble Tea v2 program inside tmux (and some other pty setups) shows a blank screen until the first event — the user resizes the window or presses a key — at which point the UI finally paints. It looks like the program hung.
Root cause
Program.Runreads the terminal size once at startup and trusts the result, checking only the error:Under tmux the pty size often isn't negotiated yet at this instant, so
term.GetSizereturns(0, 0)witherr == nil.Runthen resizes the renderer to0x0. Because the event loop only paints after it receives a message, and the only startup message is the resultingWindowSizeMsg{0,0}, the first frame is clipped to a 0x0 viewport — blank — until a realSIGWINCHarrives.This is independent of the model's
View(): even a view that ignores width entirely renders blank, because the renderer viewport is0x0.Fix
Fall back to a standard
80x24for any zero dimension, mirroring what terminal apps conventionally do. The first frame then paints, and the genuine size replaces it viaWindowSizeMsga moment later.Adds
fallbackZeroSize(a small pure helper) plus a unit test. The startupGetSizepath itself is awkward to unit-test (it needs a real tty Fd), so the fallback logic is factored into a tested helper.Testing
go test .passes.