From 0d331e0adecbaf8e6e6fb42cfd76d37f4cbac4fb Mon Sep 17 00:00:00 2001 From: Jarrod Watts Date: Sun, 5 Apr 2026 10:59:33 +1000 Subject: [PATCH] fix(render): keep compact usage windows labeled on wrap --- src/render/session-line.ts | 5 +++-- tests/render-width.test.js | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/render/session-line.ts b/src/render/session-line.ts index 30df679..f06bdb9 100644 --- a/src/render/session-line.ts +++ b/src/render/session-line.ts @@ -188,9 +188,10 @@ export function renderSessionLine(ctx: RenderContext): string { barWidth, forceLabel: true, }); - parts.push(`${fiveHourPart} | ${sevenDayPart}`); + parts.push(`${label(t('label.usage'), colors)} ${fiveHourPart}`); + parts.push(sevenDayPart); } else { - parts.push(fiveHourPart); + parts.push(`${label(t('label.usage'), colors)} ${fiveHourPart}`); } } } diff --git a/tests/render-width.test.js b/tests/render-width.test.js index fe75d37..93fff2e 100644 --- a/tests/render-width.test.js +++ b/tests/render-width.test.js @@ -297,7 +297,33 @@ test('render falls back to a safe default width when no terminal size is availab }); assert.ok(lines.length > 1, 'should wrap output instead of emitting one oversized line'); - assert.ok(lines.every(line => displayWidth(line) <= 40), 'all lines should fit the safe fallback width'); + assert.ok(lines.every(line => displayWidth(line) <= 80), 'all lines should fit the safe fallback width'); +}); + +test('render does not strand a bare 5h continuation line in compact mode', () => { + const ctx = baseContext(); + ctx.config.lineLayout = 'compact'; + ctx.config.display.usageBarEnabled = false; + ctx.config.display.showConfigCounts = false; + ctx.stdin.cwd = '/tmp/project'; + ctx.usageData = { + planName: 'Pro', + fiveHour: 30, + sevenDay: 85, + fiveHourResetAt: new Date(Date.now() + 60 * 60 * 1000), + sevenDayResetAt: new Date(Date.now() + 28 * 60 * 60 * 1000), + }; + + let lines = []; + withColumns(process.stdout, undefined, () => { + withColumns(process.stderr, 40, () => { + lines = captureRender(ctx); + }); + }); + + assert.ok(lines.some(line => line.includes('Usage 5h 30%')), `expected usage window to keep its label: ${lines.join(' | ')}`); + assert.ok(lines.some(line => line.includes('Weekly 85%')), `expected weekly usage window to render: ${lines.join(' | ')}`); + assert.ok(!lines.some(line => line.startsWith('5h ')), `did not expect a bare 5h continuation line: ${lines.join(' | ')}`); }); test('render prefers stdout columns over COLUMNS env fallback', () => {