mirror of
https://github.com/jarrodwatts/claude-hud.git
synced 2026-05-12 17:22:41 +00:00
fix: wrap HUD output when terminal width is unavailable
This commit is contained in:
@@ -213,6 +213,47 @@ test('render falls back to stderr.columns when stdout.columns is unavailable', (
|
||||
assert.ok(lines.some(line => displayWidth(line) > 10), 'stderr width should override COLUMNS fallback');
|
||||
});
|
||||
|
||||
test('render falls back to a safe default width when no terminal size is available', () => {
|
||||
const ctx = baseContext();
|
||||
ctx.stdin.model = { display_name: 'Sonnet 4.6' };
|
||||
ctx.stdin.cwd = '/tmp/very-long-project-name-for-ghostty-fallback-check';
|
||||
ctx.gitStatus = {
|
||||
branch: 'feature/ghostty-width-fallback',
|
||||
isDirty: true,
|
||||
ahead: 0,
|
||||
behind: 0,
|
||||
fileStats: { modified: 2, added: 1, deleted: 0, untracked: 1 },
|
||||
};
|
||||
ctx.config.gitStatus.showFileStats = true;
|
||||
ctx.usageData = {
|
||||
planName: 'Pro',
|
||||
fiveHour: 42,
|
||||
sevenDay: 12,
|
||||
fiveHourResetAt: new Date(Date.now() + 2 * 60 * 60 * 1000),
|
||||
sevenDayResetAt: new Date(Date.now() + 24 * 60 * 60 * 1000),
|
||||
};
|
||||
|
||||
const originalEnvColumns = process.env.COLUMNS;
|
||||
let lines = [];
|
||||
withColumns(process.stdout, undefined, () => {
|
||||
withColumns(process.stderr, undefined, () => {
|
||||
delete process.env.COLUMNS;
|
||||
try {
|
||||
lines = captureRender(ctx);
|
||||
} finally {
|
||||
if (originalEnvColumns === undefined) {
|
||||
delete process.env.COLUMNS;
|
||||
} else {
|
||||
process.env.COLUMNS = originalEnvColumns;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
test('render prefers stdout columns over COLUMNS env fallback', () => {
|
||||
const ctx = baseContext();
|
||||
ctx.stdin.cwd = '/tmp/very-long-project-name-for-width-checking';
|
||||
|
||||
Reference in New Issue
Block a user