@giladbarnea/pi-pretty-bash 1.0.6 → 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 +26 -10
- 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. Collapsed results show ten visual tail rows; expansion shows the complete 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
|
@@ -12,8 +12,10 @@ import { truncateToWidth, visibleWidth, wrapTextWithAnsi, type Component } from
|
|
|
12
12
|
import { highlight } from "cli-highlight";
|
|
13
13
|
|
|
14
14
|
const JSON_HIGHLIGHT_MAX_BYTES = 200 * 1024;
|
|
15
|
-
const
|
|
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
|
*/
|
|
@@ -96,10 +110,10 @@ function box(rows: string[], width: number, theme: Theme, caption = ""): string[
|
|
|
96
110
|
];
|
|
97
111
|
}
|
|
98
112
|
|
|
99
|
-
/**
|
|
100
|
-
* @example commandRows({command: "echo hi"}, theme, false).render(80) // A syntax-colored Bash header.
|
|
113
|
+
/** Draw the command, using a numbered box only for multiline input; collapsed boxes hide their middle rows.
|
|
114
|
+
* @example commandRows({command: "echo hi"}, theme, false, false).render(80) // A syntax-colored Bash header.
|
|
101
115
|
*/
|
|
102
|
-
function commandRows(args: BashArguments, theme: Theme, pending: boolean): Component {
|
|
116
|
+
function commandRows(args: BashArguments, theme: Theme, pending: boolean, expanded: boolean): Component {
|
|
103
117
|
const command = displayText(args.command ?? "");
|
|
104
118
|
const sourceLines = command.split("\n");
|
|
105
119
|
const highlighted = bashColors(command, theme).split("\n");
|
|
@@ -124,8 +138,10 @@ function commandRows(args: BashArguments, theme: Theme, pending: boolean): Compo
|
|
|
124
138
|
const number = segmentIndex === 0 ? theme.fg("muted", String(index + 1).padStart(numberWidth)) : " ".repeat(numberWidth);
|
|
125
139
|
return numberWidth ? `${number} ${segment}` : segment;
|
|
126
140
|
}));
|
|
127
|
-
return [header, ...box(rows, width, theme)];
|
|
128
|
-
|
|
141
|
+
if (expanded || rows.length <= PREVIEW_ROWS) return [header, ...box(rows, width, theme)];
|
|
142
|
+
const hint = wrapTextWithAnsi(`${theme.fg("muted", `… ${rows.length - PREVIEW_ROWS} more lines · `)}${keyHint("app.tools.expand", "to expand")}`, Math.max(1, width - 4));
|
|
143
|
+
return [header, ...box([...rows.slice(0, PREVIEW_ROWS / 2), ...hint, ...rows.slice(-PREVIEW_ROWS / 2)], width, theme)];
|
|
144
|
+
}, true);
|
|
129
145
|
}
|
|
130
146
|
|
|
131
147
|
/** Remove untrusted terminal instructions before applying renderer-owned styling.
|
|
@@ -191,7 +207,7 @@ export default function prettyBash(pi: ExtensionAPI): void {
|
|
|
191
207
|
active.add(state);
|
|
192
208
|
}
|
|
193
209
|
if (!context.isPartial) finish(state);
|
|
194
|
-
return commandRows((args ?? {}) as BashArguments, theme, context.executionStarted && context.isPartial && state.endedAt === undefined);
|
|
210
|
+
return commandRows((args ?? {}) as BashArguments, theme, context.executionStarted && context.isPartial && state.endedAt === undefined, context.expanded);
|
|
195
211
|
},
|
|
196
212
|
renderResult(result: Result, options, theme: Theme, context: Context) {
|
|
197
213
|
const output = result.content.filter(part => part.type === "text").map(part => part.text).join("\n");
|
|
@@ -214,7 +230,7 @@ export default function prettyBash(pi: ExtensionAPI): void {
|
|
|
214
230
|
return new BashDisplay(width => {
|
|
215
231
|
if (!parsed.body.trim()) return ["", `${caption}${theme.fg("dim", " · ")}${theme.fg("muted", options.isPartial ? "waiting for output" : "no output")}`];
|
|
216
232
|
const innerWidth = Math.max(1, width - 4);
|
|
217
|
-
const { skippedCount, visualLines } = truncateToVisualLines(styled, options.expanded ? Infinity :
|
|
233
|
+
const { skippedCount, visualLines } = truncateToVisualLines(styled, options.expanded ? Infinity : PREVIEW_ROWS, innerWidth);
|
|
218
234
|
const hint = skippedCount ? wrapTextWithAnsi(`${theme.fg("muted", `… ${skippedCount} earlier lines · `)}${keyHint("app.tools.expand", "to expand")}`, innerWidth) : [];
|
|
219
235
|
const outputPath = details?.fullOutputPath ? wrapTextWithAnsi(theme.fg("muted", `Full output: ${displayText(details.fullOutputPath)}`), width) : [];
|
|
220
236
|
return ["", ...box([...hint, ...visualLines], width, theme, caption), ...outputPath];
|