@giladbarnea/pi-pretty-bash 1.0.5 → 1.0.7

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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/index.ts +18 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- last_updated: 2026-11-02T20-46
2
+ last_updated: 2026-11-13T01-55
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. 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,7 +12,7 @@ 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 OUTPUT_PREVIEW_ROWS = 10;
15
+ const PREVIEW_ROWS = 10;
16
16
  const RESET = "\x1b[0m";
17
17
 
18
18
  type BashArguments = { command?: string; timeout?: number };
@@ -96,10 +96,10 @@ function box(rows: string[], width: number, theme: Theme, caption = ""): string[
96
96
  ];
97
97
  }
98
98
 
99
- /** Keep the complete command, using a numbered box only for multiline input.
100
- * @example commandRows({command: "echo hi"}, theme, false).render(80) // A syntax-colored Bash header.
99
+ /** Draw the command, using a numbered box only for multiline input; collapsed boxes hide their middle rows.
100
+ * @example commandRows({command: "echo hi"}, theme, false, false).render(80) // A syntax-colored Bash header.
101
101
  */
102
- function commandRows(args: BashArguments, theme: Theme, pending: boolean): Component {
102
+ function commandRows(args: BashArguments, theme: Theme, pending: boolean, expanded: boolean): Component {
103
103
  const command = displayText(args.command ?? "");
104
104
  const sourceLines = command.split("\n");
105
105
  const highlighted = bashColors(command, theme).split("\n");
@@ -124,7 +124,9 @@ function commandRows(args: BashArguments, theme: Theme, pending: boolean): Compo
124
124
  const number = segmentIndex === 0 ? theme.fg("muted", String(index + 1).padStart(numberWidth)) : " ".repeat(numberWidth);
125
125
  return numberWidth ? `${number} ${segment}` : segment;
126
126
  }));
127
- return [header, ...box(rows, width, theme)];
127
+ if (expanded || rows.length <= PREVIEW_ROWS) return [header, ...box(rows, width, theme)];
128
+ const hint = wrapTextWithAnsi(`${theme.fg("muted", `… ${rows.length - PREVIEW_ROWS} more lines · `)}${keyHint("app.tools.expand", "to expand")}`, Math.max(1, width - 4));
129
+ return [header, ...box([...rows.slice(0, PREVIEW_ROWS / 2), ...hint, ...rows.slice(-PREVIEW_ROWS / 2)], width, theme)];
128
130
  });
129
131
  }
130
132
 
@@ -142,12 +144,19 @@ function parseOutput(output: string, isError: boolean, partial: boolean): Parsed
142
144
  const body = displayText(output).trimEnd();
143
145
  if (partial) return { body, status: "running" };
144
146
  if (!isError) return { body, status: "✓" };
145
- const match = /(?:^|\n)(Command exited with code (\d+)|Command aborted|Command timed out after (\d+) seconds)\s*$/.exec(body);
147
+ const match = /(?:^|\n)(Command exited with code (\d+)|Command aborted|Command timed out after (\d+) seconds(?:\. [^\n]*)?)\s*$/.exec(body);
146
148
  if (!match) return { body, status: "✗ failed" };
147
149
  const status = match[2] ? `✗ exit ${match[2]}` : match[3] ? `✗ timeout ${match[3]}s` : "✗ aborted";
148
150
  return { body: body.slice(0, match.index).trimEnd(), status };
149
151
  }
150
152
 
153
+ /** Spell a byte count in kB, using Pi's 1024-byte unit so it matches Pi's truncation notices.
154
+ * @example kilobytes(588895) // "575.1 kB"
155
+ */
156
+ function kilobytes(bytes: number): string {
157
+ return `${(bytes / 1024).toFixed(1)} kB`;
158
+ }
159
+
151
160
  /** Recognize complete JSON within the highlighting budget, without reformatting it.
152
161
  * @example isJson('{"enabled":true}') // true
153
162
  */
@@ -184,7 +193,7 @@ export default function prettyBash(pi: ExtensionAPI): void {
184
193
  active.add(state);
185
194
  }
186
195
  if (!context.isPartial) finish(state);
187
- return commandRows((args ?? {}) as BashArguments, theme, context.executionStarted && context.isPartial && state.endedAt === undefined);
196
+ return commandRows((args ?? {}) as BashArguments, theme, context.executionStarted && context.isPartial && state.endedAt === undefined, context.expanded);
188
197
  },
189
198
  renderResult(result: Result, options, theme: Theme, context: Context) {
190
199
  const output = result.content.filter(part => part.type === "text").map(part => part.text).join("\n");
@@ -200,14 +209,14 @@ export default function prettyBash(pi: ExtensionAPI): void {
200
209
  theme.fg(options.isPartial ? "warning" : context.isError ? "error" : "success", parsed.status),
201
210
  ...(duration === undefined ? [] : [theme.fg("muted", `${(duration / 1000).toFixed(1)}s`)]),
202
211
  ...(count ? [theme.fg("muted", countLabel)] : []),
203
- ...(truncation?.truncated ? [theme.fg("warning", "truncated")] : []),
212
+ ...(truncation?.truncated ? [`${theme.fg("warning", "truncated")} ${theme.fg("dim", `${kilobytes(truncation.outputBytes)} / ${kilobytes(truncation.totalBytes)}`)}`] : []),
204
213
  ].join(theme.fg("dim", " · "));
205
214
  const highlighted = !options.isPartial && !truncation?.truncated && output.length <= JSON_HIGHLIGHT_MAX_BYTES && Buffer.byteLength(output, "utf8") <= JSON_HIGHLIGHT_MAX_BYTES && isJson(parsed.body);
206
215
  const styled = highlighted ? highlightCode(parsed.body, "json").join("\n") : parsed.body.split("\n").map(line => theme.fg("toolOutput", line)).join("\n");
207
216
  return new BashDisplay(width => {
208
217
  if (!parsed.body.trim()) return ["", `${caption}${theme.fg("dim", " · ")}${theme.fg("muted", options.isPartial ? "waiting for output" : "no output")}`];
209
218
  const innerWidth = Math.max(1, width - 4);
210
- const { skippedCount, visualLines } = truncateToVisualLines(styled, options.expanded ? Infinity : OUTPUT_PREVIEW_ROWS, innerWidth);
219
+ const { skippedCount, visualLines } = truncateToVisualLines(styled, options.expanded ? Infinity : PREVIEW_ROWS, innerWidth);
211
220
  const hint = skippedCount ? wrapTextWithAnsi(`${theme.fg("muted", `… ${skippedCount} earlier lines · `)}${keyHint("app.tools.expand", "to expand")}`, innerWidth) : [];
212
221
  const outputPath = details?.fullOutputPath ? wrapTextWithAnsi(theme.fg("muted", `Full output: ${displayText(details.fullOutputPath)}`), width) : [];
213
222
  return ["", ...box([...hint, ...visualLines], width, theme, caption), ...outputPath];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-pretty-bash",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "description": "Rich Bash command and result displays with syntax-colored commands and JSON output.",
6
6
  "keywords": [