Files
claude-hud/dist/render/colors.js
2026-01-19 04:03:29 +00:00

58 lines
1.9 KiB
JavaScript

export const RESET = '\x1b[0m';
const DIM = '\x1b[2m';
const RED = '\x1b[31m';
const GREEN = '\x1b[32m';
const YELLOW = '\x1b[33m';
const MAGENTA = '\x1b[35m';
const CYAN = '\x1b[36m';
const BRIGHT_BLUE = '\x1b[94m';
const BRIGHT_MAGENTA = '\x1b[95m';
export function green(text) {
return `${GREEN}${text}${RESET}`;
}
export function yellow(text) {
return `${YELLOW}${text}${RESET}`;
}
export function red(text) {
return `${RED}${text}${RESET}`;
}
export function cyan(text) {
return `${CYAN}${text}${RESET}`;
}
export function magenta(text) {
return `${MAGENTA}${text}${RESET}`;
}
export function dim(text) {
return `${DIM}${text}${RESET}`;
}
export function getContextColor(percent) {
if (percent >= 85)
return RED;
if (percent >= 70)
return YELLOW;
return GREEN;
}
export function getQuotaColor(percent) {
if (percent >= 90)
return RED;
if (percent >= 75)
return BRIGHT_MAGENTA;
return BRIGHT_BLUE;
}
export function quotaBar(percent, width = 10) {
const safeWidth = Number.isFinite(width) ? Math.max(0, Math.round(width)) : 0;
const safePercent = Number.isFinite(percent) ? Math.min(100, Math.max(0, percent)) : 0;
const filled = Math.round((safePercent / 100) * safeWidth);
const empty = safeWidth - filled;
const color = getQuotaColor(safePercent);
return `${color}${'█'.repeat(filled)}${DIM}${'░'.repeat(empty)}${RESET}`;
}
export function coloredBar(percent, width = 10) {
const safeWidth = Number.isFinite(width) ? Math.max(0, Math.round(width)) : 0;
const safePercent = Number.isFinite(percent) ? Math.min(100, Math.max(0, percent)) : 0;
const filled = Math.round((safePercent / 100) * safeWidth);
const empty = safeWidth - filled;
const color = getContextColor(safePercent);
return `${color}${'█'.repeat(filled)}${DIM}${'░'.repeat(empty)}${RESET}`;
}
//# sourceMappingURL=colors.js.map