mirror of
https://github.com/jarrodwatts/claude-hud.git
synced 2026-05-12 17:22:41 +00:00
82 lines
2.7 KiB
JavaScript
82 lines
2.7 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';
|
|
const ANSI_BY_NAME = {
|
|
red: RED,
|
|
green: GREEN,
|
|
yellow: YELLOW,
|
|
magenta: MAGENTA,
|
|
cyan: CYAN,
|
|
brightBlue: BRIGHT_BLUE,
|
|
brightMagenta: BRIGHT_MAGENTA,
|
|
};
|
|
function resolveAnsi(name, fallback) {
|
|
if (!name) {
|
|
return fallback;
|
|
}
|
|
return ANSI_BY_NAME[name] ?? fallback;
|
|
}
|
|
function colorize(text, color) {
|
|
return `${color}${text}${RESET}`;
|
|
}
|
|
export function green(text) {
|
|
return colorize(text, GREEN);
|
|
}
|
|
export function yellow(text) {
|
|
return colorize(text, YELLOW);
|
|
}
|
|
export function red(text) {
|
|
return colorize(text, RED);
|
|
}
|
|
export function cyan(text) {
|
|
return colorize(text, CYAN);
|
|
}
|
|
export function magenta(text) {
|
|
return colorize(text, MAGENTA);
|
|
}
|
|
export function dim(text) {
|
|
return colorize(text, DIM);
|
|
}
|
|
export function warning(text, colors) {
|
|
return colorize(text, resolveAnsi(colors?.warning, YELLOW));
|
|
}
|
|
export function critical(text, colors) {
|
|
return colorize(text, resolveAnsi(colors?.critical, RED));
|
|
}
|
|
export function getContextColor(percent, colors) {
|
|
if (percent >= 85)
|
|
return resolveAnsi(colors?.critical, RED);
|
|
if (percent >= 70)
|
|
return resolveAnsi(colors?.warning, YELLOW);
|
|
return resolveAnsi(colors?.context, GREEN);
|
|
}
|
|
export function getQuotaColor(percent, colors) {
|
|
if (percent >= 90)
|
|
return resolveAnsi(colors?.critical, RED);
|
|
if (percent >= 75)
|
|
return resolveAnsi(colors?.usageWarning, BRIGHT_MAGENTA);
|
|
return resolveAnsi(colors?.usage, BRIGHT_BLUE);
|
|
}
|
|
export function quotaBar(percent, width = 10, colors) {
|
|
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, colors);
|
|
return `${color}${'█'.repeat(filled)}${DIM}${'░'.repeat(empty)}${RESET}`;
|
|
}
|
|
export function coloredBar(percent, width = 10, colors) {
|
|
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, colors);
|
|
return `${color}${'█'.repeat(filled)}${DIM}${'░'.repeat(empty)}${RESET}`;
|
|
}
|
|
//# sourceMappingURL=colors.js.map
|