@casualjim/pi-pretty 0.7.0 → 0.7.2
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/README.md +12 -24
- package/package.json +64 -70
- package/src/helpers.ts +22 -40
- package/src/index.ts +545 -506
- package/src/render.ts +309 -325
- package/src/types.ts +80 -92
- package/src/working-indicator.ts +25 -4
- package/src/tools/bash.d.ts +0 -21
- package/src/tools/bash.ts +0 -163
package/README.md
CHANGED
|
@@ -1,39 +1,27 @@
|
|
|
1
1
|
# @casualjim/pi-pretty
|
|
2
2
|
|
|
3
3
|
Fork of [@heyhuynhgiabuu/pi-pretty](https://github.com/heyhuynhgiabuu/pi-pretty)
|
|
4
|
-
(MIT)
|
|
5
|
-
[@casualjim/pi-heimdall](https://github.com/casualjim/pi-mimir/tree/main/packages/pi-heimdall):
|
|
6
|
-
pretty rendering AND the heimdall sandbox on the same `bash` tool.
|
|
4
|
+
(MIT) trimmed to the display tools it owns.
|
|
7
5
|
|
|
8
|
-
##
|
|
6
|
+
## What it does
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- **pi-heimdall** owns the `bash` tool (sandboxed execute via
|
|
14
|
-
`@casualjim/heimdall-sandbox`) and the `--no-sandbox` flag.
|
|
15
|
-
- **pi-pretty** never registers `bash` or any flag. It exports its bash
|
|
16
|
-
renderers from the `@casualjim/pi-pretty/bash-renderers` subpath, and
|
|
17
|
-
pi-heimdall attaches them to its tool — so `bash` output keeps pi-pretty
|
|
18
|
-
styling while executing through the sandbox.
|
|
8
|
+
Shiki-highlighted `read` previews, `ls` tree views with file-type icons,
|
|
9
|
+
FFF-accelerated `find`/`grep`, a prompt editor, and activity indicators.
|
|
19
10
|
|
|
20
|
-
|
|
21
|
-
previews, `ls` icons, FFF-powered `find`/`grep`, working indicator, thinking
|
|
22
|
-
shimmer) are unchanged.
|
|
11
|
+
## Bash
|
|
23
12
|
|
|
24
|
-
|
|
13
|
+
pi-pretty does not render, register, or substitute `bash`. That tool belongs to
|
|
14
|
+
pi-heimdall (sandboxed execute), and each host renders bash with its own
|
|
15
|
+
renderer: Pi's native bash definition carries `renderCall`/`renderResult`, and
|
|
16
|
+
Oh My Pi attaches its own from `@oh-my-pi/pi-tui/tools`.
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
the host SDK's description and guidelines
|
|
30
|
-
- mid-session `/sandbox on|off` works — the toggle and the tool live in the
|
|
31
|
-
same extension now
|
|
18
|
+
Since pi 0.87.1, two extensions registering the same tool or flag is a hard
|
|
19
|
+
load error, so heimdall owns `bash` and the `--no-sandbox` flag, and pi-pretty
|
|
20
|
+
never touches either. Load order does not matter.
|
|
32
21
|
|
|
33
22
|
## Install
|
|
34
23
|
|
|
35
24
|
```bash
|
|
36
|
-
pi install git:github.com/casualjim/pi-mimir#subdirectory=packages/pi-heimdall
|
|
37
25
|
pi install git:github.com/casualjim/pi-mimir#subdirectory=packages/pi-pretty
|
|
38
26
|
```
|
|
39
27
|
|
package/package.json
CHANGED
|
@@ -1,71 +1,65 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"dependencies": {
|
|
67
|
-
"@ff-labs/fff-node": "^0.10.0",
|
|
68
|
-
"@shikijs/cli": "^4.0.2",
|
|
69
|
-
"shiki": "4.0.2"
|
|
70
|
-
}
|
|
71
|
-
}
|
|
2
|
+
"name": "@casualjim/pi-pretty",
|
|
3
|
+
"version": "0.7.2",
|
|
4
|
+
"description": "Pretty terminal output for pi built-in tools: shiki-highlighted read previews, ls tree with icons, FFF-accelerated find/grep, prompt editor and activity indicators.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi",
|
|
7
|
+
"pi-extension",
|
|
8
|
+
"pi-package",
|
|
9
|
+
"pretty-print",
|
|
10
|
+
"shiki",
|
|
11
|
+
"syntax-highlighting",
|
|
12
|
+
"terminal"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/casualjim/pi-mimir/tree/main/packages/pi-pretty",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "casualjim",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/casualjim/pi-mimir"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src/",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": "./src/index.ts"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.0.0"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"pi": {
|
|
37
|
+
"extensions": [
|
|
38
|
+
"./src/index.ts"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@earendil-works/pi-ai": "*",
|
|
43
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
44
|
+
"@earendil-works/pi-tui": "*"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@earendil-works/pi-ai": "^0.87.1",
|
|
48
|
+
"@earendil-works/pi-coding-agent": "^0.87.1",
|
|
49
|
+
"@earendil-works/pi-tui": "^0.87.0",
|
|
50
|
+
"@types/node": "^24.13.4",
|
|
51
|
+
"jiti": "^2.7.0",
|
|
52
|
+
"typescript": "^7.0.2",
|
|
53
|
+
"vitest": "^5.0.0"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@ff-labs/fff-node": "^0.10.0",
|
|
57
|
+
"@shikijs/cli": "^4.0.2",
|
|
58
|
+
"shiki": "4.0.2"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"check:pack": "pnpm pack --dry-run",
|
|
63
|
+
"test": "vitest run"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/src/helpers.ts
CHANGED
|
@@ -9,21 +9,14 @@ import { relative } from "node:path";
|
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
10
10
|
|
|
11
11
|
export function normalizeLineEndings(text: string): string {
|
|
12
|
-
|
|
12
|
+
return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function shortPath(cwd: string, home: string, p: string): string {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function stripBashExitStatusLine(text: string): string {
|
|
23
|
-
return normalizeLineEndings(text)
|
|
24
|
-
.split("\n")
|
|
25
|
-
.filter((line) => !/^Command exited with code \d+$/i.test(line.trim()))
|
|
26
|
-
.join("\n");
|
|
16
|
+
if (!p) return "";
|
|
17
|
+
const r = relative(cwd, p);
|
|
18
|
+
if (!r.startsWith("..") && !r.startsWith("/")) return r;
|
|
19
|
+
return p.replace(home, "~");
|
|
27
20
|
}
|
|
28
21
|
|
|
29
22
|
// ---------------------------------------------------------------------------
|
|
@@ -31,45 +24,34 @@ export function stripBashExitStatusLine(text: string): string {
|
|
|
31
24
|
// ---------------------------------------------------------------------------
|
|
32
25
|
|
|
33
26
|
export function formatElapsedMs(ms: number | undefined): string {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
if (typeof ms !== "number" || !Number.isFinite(ms)) return "";
|
|
28
|
+
if (ms < 1000) return `${Math.round(ms)}ms`;
|
|
29
|
+
const s = ms / 1000;
|
|
30
|
+
return s < 10 ? `${s.toFixed(1)}s` : `${Math.round(s)}s`;
|
|
38
31
|
}
|
|
39
32
|
|
|
40
33
|
export function formatCharCount(chars: number | undefined): string {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
if (typeof chars !== "number" || !Number.isFinite(chars) || chars <= 0) return "";
|
|
35
|
+
if (chars < 1000) return `${chars} chars`;
|
|
36
|
+
if (chars < 10_000) return `${(chars / 1000).toFixed(1)}k chars`;
|
|
37
|
+
return `${Math.round(chars / 1000)}k chars`;
|
|
45
38
|
}
|
|
46
39
|
|
|
47
40
|
export const ELAPSED_KEY = "__prettyElapsedMs";
|
|
48
41
|
export const CHARS_KEY = "__prettyOutputChars";
|
|
49
42
|
|
|
50
|
-
// ---------------------------------------------------------------------------
|
|
51
|
-
// Infer bash exit code
|
|
52
|
-
// ---------------------------------------------------------------------------
|
|
53
|
-
|
|
54
|
-
export function inferBashExitCode(text: string, fallback: number | null): number | null {
|
|
55
|
-
const exitMatch = text.match(/(?:exit code|exited with(?: code)?|exit status)[:\s]*(\d+)/i);
|
|
56
|
-
if (exitMatch) return Number(exitMatch[1]);
|
|
57
|
-
if (text.includes("command not found") || text.includes("No such file")) return 1;
|
|
58
|
-
return fallback;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
43
|
// ---------------------------------------------------------------------------
|
|
62
44
|
// Compact error lines
|
|
63
45
|
// ---------------------------------------------------------------------------
|
|
64
46
|
|
|
65
47
|
export function compactErrorLines(error: string): string[] {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
48
|
+
const compactedLines: string[] = [];
|
|
49
|
+
let previousBlank = false;
|
|
50
|
+
for (const line of normalizeLineEndings(error).trim().split("\n")) {
|
|
51
|
+
const isBlank = line.trim() === "";
|
|
52
|
+
if (isBlank && previousBlank) continue;
|
|
53
|
+
compactedLines.push(line);
|
|
54
|
+
previousBlank = isBlank;
|
|
55
|
+
}
|
|
56
|
+
return compactedLines;
|
|
75
57
|
}
|