import type { SegmentContext, SemanticColor } from "../config/types.ts"; import { fg } from "../theme/theme.ts"; // ═══════════════════════════════════════════════════════════════════════════ // Helpers // ═══════════════════════════════════════════════════════════════════════════ export function color( ctx: SegmentContext, semantic: SemanticColor, text: string, ): string { return fg(ctx.theme, semantic, text, ctx.colors); } export function withIcon(icon: string, text: string): string { return icon ? `${icon} ${text}` : text; } export function formatTokens(n: number): string { if (n < 1000) return n.toString(); if (n < 10000) return `${(n / 1000).toFixed(1)}k`; if (n < 1000000) return `${Math.round(n / 1000)}k`; if (n < 10000000) return `${(n / 1000000).toFixed(1)}M`; return `${Math.round(n / 1000000)}M`; } export function formatDuration(ms: number): string { const seconds = Math.floor(ms / 1000); const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); if (hours > 0) return `${hours}h${minutes % 60}m`; if (minutes > 0) return `${minutes}m${seconds % 60}s`; return `${seconds}s`; }