From c0b5750a370a9155a528aa5e4419918366e526d0 Mon Sep 17 00:00:00 2001 From: martinvlad Date: Tue, 13 Oct 2026 08:14:11 -0700 Subject: [PATCH] fix(console): draw the tui at the default size when the terminal reports 0 columns Some ptys report a size of 0 (docker exec without -t, CI `script` wrappers). `columns ?? 100` keeps the 0, so paint() took the too-narrow branch and sliced its notice to max(1, 0) = 1 character: the tui printed "T" on every redraw. A 0 or missing size now means "unknown" and uses the defaults (100x30), for columns and rows, in paint, --plain and paging. Refs #4115 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RMjr52YGVk9fkqtNvb5jg2 --- plugins/ruflo-console/tests/tui-nav.spec.ts | 14 ++++++++++++++ plugins/ruflo-console/tui/run.ts | 11 +++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/plugins/ruflo-console/tests/tui-nav.spec.ts b/plugins/ruflo-console/tests/tui-nav.spec.ts index 3fe9174101..5905e82303 100644 --- a/plugins/ruflo-console/tests/tui-nav.spec.ts +++ b/plugins/ruflo-console/tests/tui-nav.spec.ts @@ -158,6 +158,20 @@ describe('every page, on a host with no Claude session and no mouse', () => { }) describe('the terminal loop', () => { + it('a terminal that reports 0 columns draws the page at the default width, not a repeated "T" (#4115)', async () => { + const t = terminal(0, 0) + const running = runTui({ cwd: project, home: join(root, 'home') }, t.io) + + await settle() + t.press('q') + await expect(running).resolves.toBe(0) + + const text = plain(t.out.join('')) + + expect(text).toMatch(/1 Overview {1,3}2 Cost/) + expect(text).not.toContain('Too narrow') + }) + it('jumps to a page on a digit, cycles with tab and shift-tab, and the page bar follows', async () => { const t = terminal() const running = runTui({ cwd: project, home: join(root, 'home') }, t.io) diff --git a/plugins/ruflo-console/tui/run.ts b/plugins/ruflo-console/tui/run.ts index e6f3e76097..6edac9f5fb 100644 --- a/plugins/ruflo-console/tui/run.ts +++ b/plugins/ruflo-console/tui/run.ts @@ -117,10 +117,13 @@ export function keyOf(chunk: string): Key { } } +/** A terminal that reports 0 (or nothing) does not know its size; some `docker exec` without -t and CI `script` wrappers do. Use the default rather than calling it too narrow (#4115). */ +const sized = (value: number | undefined, fallback: number): number => (value !== undefined && Number.isFinite(value) && value > 0 ? value : fallback) + function paint(session: Session, io: TuiIO, depth: Depth, scroll: number, clear = false): number { const ai = session.page === 'ai' ? session.ai : null - const raw = io.stdout.columns ?? 100 - const rows = Math.max(5, io.stdout.rows ?? 30) + const raw = sized(io.stdout.columns, 100) + const rows = Math.max(5, sized(io.stdout.rows, 30)) const reset = clear ? `${ESC}[2J` : '' // Too narrow for a page: say so in a line that fits, rather than a squeezed frame of broken cards. @@ -157,7 +160,7 @@ function paint(session: Session, io: TuiIO, depth: Depth, scroll: number, clear async function once(session: Session, io: TuiIO, view: TuiView): Promise { session.show(view) await session.refresh() - const columns = Math.max(MIN_COLUMNS, Math.min(200, io.stdout.columns ?? 100)) + const columns = Math.max(MIN_COLUMNS, Math.min(200, sized(io.stdout.columns, 100))) io.stdout.write(`${navLine(view, columns, 'none')}\n${session.frame(columns, 'none').join('\n')}\n`) @@ -199,7 +202,7 @@ export async function runTui(options: TuiOptions, io: TuiIO): Promise { if (view === 'ai' && session.ai !== null && session.ai.press(chunk.toString()).consumed) return draw() const key = keyOf(chunk.toString()) - const page = Math.max(1, (io.stdout.rows ?? 30) - 2) + const page = Math.max(1, sized(io.stdout.rows, 30) - 2) if (key === 'quit') return finish() if (typeof key === 'object' && key !== null) (view = key.page), (scroll = 0), session.show(view), view === 'ai' && session.ai?.enter()