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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RMjr52YGVk9fkqtNvb5jg2
This commit is contained in:
martinvladandClaude Opus 5.5 committed 2026-10-13 08:14:11 -07:00
1 parent 55e2c9011c
commit c0b5750a37
2 files changed
+21 -4

No files matched your search

@@ -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)
+7 -4
View File
@@ -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<number> {
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<number> {
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()