@giladbarnea/pi-pretty-bash 1.0.7 → 1.0.8
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 +2 -2
- package/index.ts +17 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
last_updated: 2026-11-
|
|
2
|
+
last_updated: 2026-11-13T11-15
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
<div align="center">
|
|
@@ -27,7 +27,7 @@ Alternatively, install from Git with `pi install git:github.com/giladbarnea/pi-p
|
|
|
27
27
|
|
|
28
28
|
## Rich Bash layout without replacing the Bash tool
|
|
29
29
|
|
|
30
|
-
Short commands get syntax colors in the header. Multiline commands get numbered boxes, and long commands wrap without losing their end. Result boxes show status, elapsed time and line counts. Pi's tool expansion toggle governs both boxes. Collapsed, a command box over ten rows shows its first and last five, and results show ten visual tail rows; expansion shows the complete command and returned text.
|
|
30
|
+
Short commands get syntax colors in the header. Multiline commands get numbered boxes, and long commands wrap without losing their end. Inputs have a black background; output keeps the terminal background so the two stay distinct. Result boxes show status, elapsed time and line counts. Pi's tool expansion toggle governs both boxes. Collapsed, a command box over ten rows shows its first and last five, and results show ten visual tail rows; expansion shows the complete command and returned text.
|
|
31
31
|
|
|
32
32
|
The Bash palette preserves the former personal `bash-rich-highlight` choices, including function colors for built-ins. It uses `cli-highlight` with Pi theme colors, not the former HTML parser or hardcoded installation paths.
|
|
33
33
|
|
package/index.ts
CHANGED
|
@@ -14,6 +14,8 @@ import { highlight } from "cli-highlight";
|
|
|
14
14
|
const JSON_HIGHLIGHT_MAX_BYTES = 200 * 1024;
|
|
15
15
|
const PREVIEW_ROWS = 10;
|
|
16
16
|
const RESET = "\x1b[0m";
|
|
17
|
+
const BLACK_BACKGROUND = "\x1b[48;5;16m";
|
|
18
|
+
const SURFACE_TEXT = "\x1b[38;5;252m";
|
|
17
19
|
|
|
18
20
|
type BashArguments = { command?: string; timeout?: number };
|
|
19
21
|
type Result = Parameters<NonNullable<ToolRenderers["renderResult"]>>[0];
|
|
@@ -25,9 +27,11 @@ class BashDisplay implements Component {
|
|
|
25
27
|
private width?: number;
|
|
26
28
|
private lines?: string[];
|
|
27
29
|
private draw: (width: number) => string[];
|
|
30
|
+
private background: boolean;
|
|
28
31
|
|
|
29
|
-
constructor(draw: (width: number) => string[]) {
|
|
32
|
+
constructor(draw: (width: number) => string[], background = false) {
|
|
30
33
|
this.draw = draw;
|
|
34
|
+
this.background = background;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
invalidate(): void {
|
|
@@ -37,11 +41,21 @@ class BashDisplay implements Component {
|
|
|
37
41
|
render(width: number): string[] {
|
|
38
42
|
if (this.lines && this.width === width) return this.lines;
|
|
39
43
|
this.width = width;
|
|
40
|
-
this.lines = this.draw(Math.max(1, width - 1)).map(line => truncateToWidth(line, width));
|
|
44
|
+
this.lines = this.draw(Math.max(1, width - 1)).map(line => this.background ? blackBackground(line, width) : truncateToWidth(line, width));
|
|
41
45
|
return this.lines;
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
/** Fill a terminal row with black, restoring its surface colors after nested styling resets.
|
|
50
|
+
* @example stripVTControlCharacters(blackBackground("git status", 12)) // "git status "
|
|
51
|
+
*/
|
|
52
|
+
function blackBackground(line: string, width: number): string {
|
|
53
|
+
const padded = truncateToWidth(line, width, "...", true);
|
|
54
|
+
const styled = padded.replace(/\x1b\[(?:0)?m/g, `$&${SURFACE_TEXT}${BLACK_BACKGROUND}`)
|
|
55
|
+
.replace(/\x1b\[(?:22;)?39m/g, `$&${SURFACE_TEXT}`).replaceAll("\x1b[49m", BLACK_BACKGROUND);
|
|
56
|
+
return `${SURFACE_TEXT}${BLACK_BACKGROUND}${styled}${RESET}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
45
59
|
/** Apply the old Bash token palette without its hand-written HTML parser.
|
|
46
60
|
* @example bashColors('echo "$HOME"', theme) // Built-ins use syntaxFunction; variables use syntaxVariable.
|
|
47
61
|
*/
|
|
@@ -127,7 +141,7 @@ function commandRows(args: BashArguments, theme: Theme, pending: boolean, expand
|
|
|
127
141
|
if (expanded || rows.length <= PREVIEW_ROWS) return [header, ...box(rows, width, theme)];
|
|
128
142
|
const hint = wrapTextWithAnsi(`${theme.fg("muted", `… ${rows.length - PREVIEW_ROWS} more lines · `)}${keyHint("app.tools.expand", "to expand")}`, Math.max(1, width - 4));
|
|
129
143
|
return [header, ...box([...rows.slice(0, PREVIEW_ROWS / 2), ...hint, ...rows.slice(-PREVIEW_ROWS / 2)], width, theme)];
|
|
130
|
-
});
|
|
144
|
+
}, true);
|
|
131
145
|
}
|
|
132
146
|
|
|
133
147
|
/** Remove untrusted terminal instructions before applying renderer-owned styling.
|