jfl 0.6.0 → 0.6.1
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
CHANGED
|
@@ -12,10 +12,24 @@ import type { PiTheme } from "./types.js"
|
|
|
12
12
|
|
|
13
13
|
// ─── Shared helpers ──────────────────────────────────────────────────────────
|
|
14
14
|
|
|
15
|
+
function visibleLen(text: string): number {
|
|
16
|
+
return text.replace(/\x1b\[[0-9;]*m/g, "").length
|
|
17
|
+
}
|
|
18
|
+
|
|
15
19
|
function truncLine(text: string, maxW: number): string {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
if (visibleLen(text) <= maxW) return text
|
|
21
|
+
// Walk char-by-char, skipping ANSI sequences, until we hit maxW visible chars
|
|
22
|
+
let visible = 0
|
|
23
|
+
let i = 0
|
|
24
|
+
while (i < text.length && visible < maxW - 1) {
|
|
25
|
+
if (text[i] === "\x1b" && text[i + 1] === "[") {
|
|
26
|
+
const end = text.indexOf("m", i)
|
|
27
|
+
if (end !== -1) { i = end + 1; continue }
|
|
28
|
+
}
|
|
29
|
+
visible++
|
|
30
|
+
i++
|
|
31
|
+
}
|
|
32
|
+
return text.slice(0, i) + "\x1b[0m…"
|
|
19
33
|
}
|
|
20
34
|
|
|
21
35
|
function wrapText(text: string, width: number): string[] {
|