fix(render): keep compact usage windows labeled on wrap

This commit is contained in:
Jarrod Watts
2026-04-05 10:59:33 +10:00
parent 71d0a0d94d
commit 0d331e0ade
2 changed files with 30 additions and 3 deletions

View File

@@ -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}`);
}
}
}

View File

@@ -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', () => {