Files
claude-hud/dist/render/index.js

86 lines
2.7 KiB
JavaScript
Raw Normal View History

2026-01-05 04:06:24 +00:00
import { renderSessionLine } from './session-line.js';
import { renderToolsLine } from './tools-line.js';
import { renderAgentsLine } from './agents-line.js';
import { renderTodosLine } from './todos-line.js';
feat(layout): add expanded multi-line layout mode (#76) * feat(layout): add expanded multi-line layout mode Split the overloaded session line into semantic lines for better readability: - Identity line: model, plan, context bar, duration - Project line: path, git status - Environment line: config counts (CLAUDE.md, rules, MCPs, hooks) - Usage line: rate limits with reset times New config options: - `lineLayout`: 'compact' | 'expanded' (default: expanded for new users) - `showSeparators`: boolean (orthogonal to layout) - `usageThreshold`: show usage line only when >= N% - `environmentThreshold`: show env line only when counts >= N Backward compatible: old `layout` config is automatically migrated. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address code review feedback - Fix usage threshold to use max(5h, 7d) so high 7d usage isn't hidden when 5h is null - Update stale comment in session-line.ts (now compact layout only) - Remove non-null assertions in identity.ts by hoisting planName Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: apply thresholds to compact layout for consistency - Add environmentThreshold gating to config counts in compact mode - Add usageThreshold with max(5h, 7d) logic to usage in compact mode - Remove non-null assertion for planName (same fix as identity.ts) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: update tests for new lineLayout config schema - Update config.test.js to validate lineLayout instead of layout - Update render.test.js to use lineLayout and showSeparators - Update index.test.js mock config with new schema - Update integration test expected output for expanded default Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 12:17:36 +11:00
import { renderIdentityLine, renderProjectLine, renderEnvironmentLine, renderUsageLine, } from './lines/index.js';
2026-01-07 05:00:50 +00:00
import { dim, RESET } from './colors.js';
function stripAnsi(str) {
2026-01-07 05:00:50 +00:00
// eslint-disable-next-line no-control-regex
return str.replace(/\x1b\[[0-9;]*m/g, '');
2026-01-07 05:00:50 +00:00
}
function visualLength(str) {
return stripAnsi(str).length;
}
function makeSeparator(length) {
return dim('─'.repeat(Math.max(length, 20)));
2026-01-07 05:00:50 +00:00
}
feat(layout): add expanded multi-line layout mode (#76) * feat(layout): add expanded multi-line layout mode Split the overloaded session line into semantic lines for better readability: - Identity line: model, plan, context bar, duration - Project line: path, git status - Environment line: config counts (CLAUDE.md, rules, MCPs, hooks) - Usage line: rate limits with reset times New config options: - `lineLayout`: 'compact' | 'expanded' (default: expanded for new users) - `showSeparators`: boolean (orthogonal to layout) - `usageThreshold`: show usage line only when >= N% - `environmentThreshold`: show env line only when counts >= N Backward compatible: old `layout` config is automatically migrated. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address code review feedback - Fix usage threshold to use max(5h, 7d) so high 7d usage isn't hidden when 5h is null - Update stale comment in session-line.ts (now compact layout only) - Remove non-null assertions in identity.ts by hoisting planName Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: apply thresholds to compact layout for consistency - Add environmentThreshold gating to config counts in compact mode - Add usageThreshold with max(5h, 7d) logic to usage in compact mode - Remove non-null assertion for planName (same fix as identity.ts) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: update tests for new lineLayout config schema - Update config.test.js to validate lineLayout instead of layout - Update render.test.js to use lineLayout and showSeparators - Update index.test.js mock config with new schema - Update integration test expected output for expanded default Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 12:17:36 +11:00
function collectActivityLines(ctx) {
2026-01-07 05:00:50 +00:00
const activityLines = [];
feat(layout): add expanded multi-line layout mode (#76) * feat(layout): add expanded multi-line layout mode Split the overloaded session line into semantic lines for better readability: - Identity line: model, plan, context bar, duration - Project line: path, git status - Environment line: config counts (CLAUDE.md, rules, MCPs, hooks) - Usage line: rate limits with reset times New config options: - `lineLayout`: 'compact' | 'expanded' (default: expanded for new users) - `showSeparators`: boolean (orthogonal to layout) - `usageThreshold`: show usage line only when >= N% - `environmentThreshold`: show env line only when counts >= N Backward compatible: old `layout` config is automatically migrated. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address code review feedback - Fix usage threshold to use max(5h, 7d) so high 7d usage isn't hidden when 5h is null - Update stale comment in session-line.ts (now compact layout only) - Remove non-null assertions in identity.ts by hoisting planName Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: apply thresholds to compact layout for consistency - Add environmentThreshold gating to config counts in compact mode - Add usageThreshold with max(5h, 7d) logic to usage in compact mode - Remove non-null assertion for planName (same fix as identity.ts) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: update tests for new lineLayout config schema - Update config.test.js to validate lineLayout instead of layout - Update render.test.js to use lineLayout and showSeparators - Update index.test.js mock config with new schema - Update integration test expected output for expanded default Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 12:17:36 +11:00
const display = ctx.config?.display;
2026-01-07 05:00:50 +00:00
if (display?.showTools !== false) {
const toolsLine = renderToolsLine(ctx);
if (toolsLine) {
activityLines.push(toolsLine);
}
}
if (display?.showAgents !== false) {
const agentsLine = renderAgentsLine(ctx);
if (agentsLine) {
activityLines.push(agentsLine);
}
}
if (display?.showTodos !== false) {
const todosLine = renderTodosLine(ctx);
if (todosLine) {
activityLines.push(todosLine);
}
}
feat(layout): add expanded multi-line layout mode (#76) * feat(layout): add expanded multi-line layout mode Split the overloaded session line into semantic lines for better readability: - Identity line: model, plan, context bar, duration - Project line: path, git status - Environment line: config counts (CLAUDE.md, rules, MCPs, hooks) - Usage line: rate limits with reset times New config options: - `lineLayout`: 'compact' | 'expanded' (default: expanded for new users) - `showSeparators`: boolean (orthogonal to layout) - `usageThreshold`: show usage line only when >= N% - `environmentThreshold`: show env line only when counts >= N Backward compatible: old `layout` config is automatically migrated. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address code review feedback - Fix usage threshold to use max(5h, 7d) so high 7d usage isn't hidden when 5h is null - Update stale comment in session-line.ts (now compact layout only) - Remove non-null assertions in identity.ts by hoisting planName Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: apply thresholds to compact layout for consistency - Add environmentThreshold gating to config counts in compact mode - Add usageThreshold with max(5h, 7d) logic to usage in compact mode - Remove non-null assertion for planName (same fix as identity.ts) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: update tests for new lineLayout config schema - Update config.test.js to validate lineLayout instead of layout - Update render.test.js to use lineLayout and showSeparators - Update index.test.js mock config with new schema - Update integration test expected output for expanded default Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 12:17:36 +11:00
return activityLines;
}
function renderCompact(ctx) {
const lines = [];
2026-01-05 04:06:24 +00:00
const sessionLine = renderSessionLine(ctx);
if (sessionLine) {
lines.push(sessionLine);
}
feat(layout): add expanded multi-line layout mode (#76) * feat(layout): add expanded multi-line layout mode Split the overloaded session line into semantic lines for better readability: - Identity line: model, plan, context bar, duration - Project line: path, git status - Environment line: config counts (CLAUDE.md, rules, MCPs, hooks) - Usage line: rate limits with reset times New config options: - `lineLayout`: 'compact' | 'expanded' (default: expanded for new users) - `showSeparators`: boolean (orthogonal to layout) - `usageThreshold`: show usage line only when >= N% - `environmentThreshold`: show env line only when counts >= N Backward compatible: old `layout` config is automatically migrated. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address code review feedback - Fix usage threshold to use max(5h, 7d) so high 7d usage isn't hidden when 5h is null - Update stale comment in session-line.ts (now compact layout only) - Remove non-null assertions in identity.ts by hoisting planName Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: apply thresholds to compact layout for consistency - Add environmentThreshold gating to config counts in compact mode - Add usageThreshold with max(5h, 7d) logic to usage in compact mode - Remove non-null assertion for planName (same fix as identity.ts) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: update tests for new lineLayout config schema - Update config.test.js to validate lineLayout instead of layout - Update render.test.js to use lineLayout and showSeparators - Update index.test.js mock config with new schema - Update integration test expected output for expanded default Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 12:17:36 +11:00
return lines;
}
function renderExpanded(ctx) {
const lines = [];
const projectLine = renderProjectLine(ctx);
if (projectLine) {
lines.push(projectLine);
}
const identityLine = renderIdentityLine(ctx);
const usageLine = renderUsageLine(ctx);
if (identityLine && usageLine) {
lines.push(`${identityLine} \u2502 ${usageLine}`);
}
else if (identityLine) {
lines.push(identityLine);
}
feat(layout): add expanded multi-line layout mode (#76) * feat(layout): add expanded multi-line layout mode Split the overloaded session line into semantic lines for better readability: - Identity line: model, plan, context bar, duration - Project line: path, git status - Environment line: config counts (CLAUDE.md, rules, MCPs, hooks) - Usage line: rate limits with reset times New config options: - `lineLayout`: 'compact' | 'expanded' (default: expanded for new users) - `showSeparators`: boolean (orthogonal to layout) - `usageThreshold`: show usage line only when >= N% - `environmentThreshold`: show env line only when counts >= N Backward compatible: old `layout` config is automatically migrated. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address code review feedback - Fix usage threshold to use max(5h, 7d) so high 7d usage isn't hidden when 5h is null - Update stale comment in session-line.ts (now compact layout only) - Remove non-null assertions in identity.ts by hoisting planName Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: apply thresholds to compact layout for consistency - Add environmentThreshold gating to config counts in compact mode - Add usageThreshold with max(5h, 7d) logic to usage in compact mode - Remove non-null assertion for planName (same fix as identity.ts) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: update tests for new lineLayout config schema - Update config.test.js to validate lineLayout instead of layout - Update render.test.js to use lineLayout and showSeparators - Update index.test.js mock config with new schema - Update integration test expected output for expanded default Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 12:17:36 +11:00
const environmentLine = renderEnvironmentLine(ctx);
if (environmentLine) {
lines.push(environmentLine);
}
return lines;
}
export function render(ctx) {
const lineLayout = ctx.config?.lineLayout ?? 'expanded';
const showSeparators = ctx.config?.showSeparators ?? false;
const headerLines = lineLayout === 'expanded'
? renderExpanded(ctx)
: renderCompact(ctx);
feat(layout): add expanded multi-line layout mode (#76) * feat(layout): add expanded multi-line layout mode Split the overloaded session line into semantic lines for better readability: - Identity line: model, plan, context bar, duration - Project line: path, git status - Environment line: config counts (CLAUDE.md, rules, MCPs, hooks) - Usage line: rate limits with reset times New config options: - `lineLayout`: 'compact' | 'expanded' (default: expanded for new users) - `showSeparators`: boolean (orthogonal to layout) - `usageThreshold`: show usage line only when >= N% - `environmentThreshold`: show env line only when counts >= N Backward compatible: old `layout` config is automatically migrated. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address code review feedback - Fix usage threshold to use max(5h, 7d) so high 7d usage isn't hidden when 5h is null - Update stale comment in session-line.ts (now compact layout only) - Remove non-null assertions in identity.ts by hoisting planName Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: apply thresholds to compact layout for consistency - Add environmentThreshold gating to config counts in compact mode - Add usageThreshold with max(5h, 7d) logic to usage in compact mode - Remove non-null assertion for planName (same fix as identity.ts) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: update tests for new lineLayout config schema - Update config.test.js to validate lineLayout instead of layout - Update render.test.js to use lineLayout and showSeparators - Update index.test.js mock config with new schema - Update integration test expected output for expanded default Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 12:17:36 +11:00
const activityLines = collectActivityLines(ctx);
const lines = [...headerLines];
if (showSeparators && activityLines.length > 0) {
const maxWidth = Math.max(...headerLines.map(visualLength), 20);
lines.push(makeSeparator(maxWidth));
2026-01-05 04:06:24 +00:00
}
lines.push(...activityLines);
for (const line of lines) {
const outputLine = `${RESET}${line.replace(/ /g, '\u00A0')}`;
console.log(outputLine);
2026-01-05 04:06:24 +00:00
}
}
//# sourceMappingURL=index.js.map