@xynogen/pix-pretty 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/modal-frame.ts +4 -0
- package/src/widget-format.test.ts +13 -0
- package/src/widget-format.ts +17 -0
package/package.json
CHANGED
package/src/modal-frame.ts
CHANGED
|
@@ -17,6 +17,10 @@ import {
|
|
|
17
17
|
wrapTextWithAnsi,
|
|
18
18
|
} from "@earendil-works/pi-tui";
|
|
19
19
|
|
|
20
|
+
export { truncateToWidth, visibleWidth, wrapTextWithAnsi };
|
|
21
|
+
|
|
22
|
+
// ponytail: re-export ANSI-safe wrapping via pix-pretty so consumers dedupe local wrapText (pix-mcp)
|
|
23
|
+
|
|
20
24
|
// ── Constants ─────────────────────────────────────────────────────────────────
|
|
21
25
|
|
|
22
26
|
const MIN_WIDTH = 40;
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
describeActivity,
|
|
4
4
|
fmtTokenCount,
|
|
5
5
|
formatContext,
|
|
6
|
+
formatDuration,
|
|
6
7
|
formatMs,
|
|
7
8
|
formatSpeed,
|
|
8
9
|
formatTokens,
|
|
@@ -37,6 +38,18 @@ describe("widget formatters", () => {
|
|
|
37
38
|
expect(formatMs(2_100)).toBe("2.1s");
|
|
38
39
|
});
|
|
39
40
|
|
|
41
|
+
test("formatDuration keeps 3 presentations via style param", () => {
|
|
42
|
+
expect(formatDuration(420, "bash")).toBe("420ms");
|
|
43
|
+
expect(formatDuration(2_450, "bash")).toBe("2.5s");
|
|
44
|
+
expect(formatDuration(12_400, "bash")).toBe("12s");
|
|
45
|
+
expect(formatDuration(450, "btw")).toBe("450ms");
|
|
46
|
+
expect(formatDuration(2_100, "btw")).toBe("2.1s");
|
|
47
|
+
expect(formatDuration(12_400, "btw")).toBe("12s");
|
|
48
|
+
expect(formatDuration(65_000, "btw")).toBe("1m 5s");
|
|
49
|
+
expect(formatDuration(2_100)).toBe("2.1s");
|
|
50
|
+
expect(formatDuration(2_100, "ms")).toBe(formatMs(2_100));
|
|
51
|
+
});
|
|
52
|
+
|
|
40
53
|
test("formatSpeed returns empty when there is no work", () => {
|
|
41
54
|
expect(formatSpeed(0, 1_000)).toBe("");
|
|
42
55
|
expect(formatSpeed(100, 0)).toBe("");
|
package/src/widget-format.ts
CHANGED
|
@@ -109,6 +109,23 @@ export function formatMs(ms: number): string {
|
|
|
109
109
|
return `${(ms / 1000).toFixed(1)}s`;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
/** ponytail: unified duration - keep 3 presentations via style param. */
|
|
113
|
+
export type DurationStyle = "bash" | "btw" | "ms"; // bash=ms/<10s 1dp/>10s int; btw=ms/s/m+s; ms=always s 1dp
|
|
114
|
+
export function formatDuration(ms: number, style: DurationStyle = "ms"): string {
|
|
115
|
+
const n = Math.max(0, Math.floor(ms));
|
|
116
|
+
if (style === "bash") {
|
|
117
|
+
if (n < 1_000) return `${n}ms`;
|
|
118
|
+
if (n < 10_000) return `${(n / 1_000).toFixed(1)}s`;
|
|
119
|
+
return `${Math.round(n / 1_000)}s`;
|
|
120
|
+
}
|
|
121
|
+
if (style === "btw") {
|
|
122
|
+
if (n < 1_000) return `${n}ms`;
|
|
123
|
+
if (n < 60_000) return `${(n / 1_000).toFixed(n < 10_000 ? 1 : 0)}s`;
|
|
124
|
+
return `${Math.floor(n / 60_000)}m ${Math.round((n % 60_000) / 1_000)}s`;
|
|
125
|
+
}
|
|
126
|
+
return formatMs(n);
|
|
127
|
+
}
|
|
128
|
+
|
|
112
129
|
/**
|
|
113
130
|
* Output tokens per second over a duration. "" when either input is
|
|
114
131
|
* non-positive (no work / zero elapsed) so callers can skip the segment.
|