1import { ansiFg, theme } from "./CliKit/index.ts";
2
3/** `450ms` under a second, `1.2s` at or above — shared by every renderer. */
4export const formatElapsed = (ms: number): string =>
5 ms < 1000 ? `${Math.max(0, Math.round(ms))}ms` : `${(ms / 1000).toFixed(1)}s`;
6
7export const TAIL_COLORS = [
8 ansiFg(theme.color.accent),
9 ansiFg(theme.color.info),
10 ansiFg(theme.color.danger),
11 ansiFg(theme.color.warning),
12 ansiFg(theme.color.accentBright),
13 ansiFg(theme.color.muted),
14 ansiFg(theme.color.accentMuted),
15 ansiFg(theme.color.success),
16];
17
18export const formatLocalTimestamp = (date: Date): string => {
19 const y = date.getFullYear();
20 const mo = String(date.getMonth() + 1).padStart(2, "0");
21 const d = String(date.getDate()).padStart(2, "0");
22 const h = String(date.getHours()).padStart(2, "0");
23 const mi = String(date.getMinutes()).padStart(2, "0");
24 const s = String(date.getSeconds()).padStart(2, "0");
25 const ms = String(date.getMilliseconds()).padStart(3, "0");
26 const tz =
27 new Intl.DateTimeFormat("en-US", { timeZoneName: "short" })
28 .formatToParts(date)
29 .find((part) => part.type === "timeZoneName")?.value ?? "";
30 return `${y}-${mo}-${d} ${h}:${mi}:${s}.${ms} ${tz}`;
31};