@giladbarnea/pi-pretty-bash 1.0.5 → 1.0.6
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/index.ts +9 -2
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -142,12 +142,19 @@ function parseOutput(output: string, isError: boolean, partial: boolean): Parsed
|
|
|
142
142
|
const body = displayText(output).trimEnd();
|
|
143
143
|
if (partial) return { body, status: "running" };
|
|
144
144
|
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);
|
|
145
|
+
const match = /(?:^|\n)(Command exited with code (\d+)|Command aborted|Command timed out after (\d+) seconds(?:\. [^\n]*)?)\s*$/.exec(body);
|
|
146
146
|
if (!match) return { body, status: "✗ failed" };
|
|
147
147
|
const status = match[2] ? `✗ exit ${match[2]}` : match[3] ? `✗ timeout ${match[3]}s` : "✗ aborted";
|
|
148
148
|
return { body: body.slice(0, match.index).trimEnd(), status };
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
/** Spell a byte count in kB, using Pi's 1024-byte unit so it matches Pi's truncation notices.
|
|
152
|
+
* @example kilobytes(588895) // "575.1 kB"
|
|
153
|
+
*/
|
|
154
|
+
function kilobytes(bytes: number): string {
|
|
155
|
+
return `${(bytes / 1024).toFixed(1)} kB`;
|
|
156
|
+
}
|
|
157
|
+
|
|
151
158
|
/** Recognize complete JSON within the highlighting budget, without reformatting it.
|
|
152
159
|
* @example isJson('{"enabled":true}') // true
|
|
153
160
|
*/
|
|
@@ -200,7 +207,7 @@ export default function prettyBash(pi: ExtensionAPI): void {
|
|
|
200
207
|
theme.fg(options.isPartial ? "warning" : context.isError ? "error" : "success", parsed.status),
|
|
201
208
|
...(duration === undefined ? [] : [theme.fg("muted", `${(duration / 1000).toFixed(1)}s`)]),
|
|
202
209
|
...(count ? [theme.fg("muted", countLabel)] : []),
|
|
203
|
-
...(truncation?.truncated ? [theme.fg("warning", "truncated")] : []),
|
|
210
|
+
...(truncation?.truncated ? [`${theme.fg("warning", "truncated")} ${theme.fg("dim", `${kilobytes(truncation.outputBytes)} / ${kilobytes(truncation.totalBytes)}`)}`] : []),
|
|
204
211
|
].join(theme.fg("dim", " · "));
|
|
205
212
|
const highlighted = !options.isPartial && !truncation?.truncated && output.length <= JSON_HIGHLIGHT_MAX_BYTES && Buffer.byteLength(output, "utf8") <= JSON_HIGHLIGHT_MAX_BYTES && isJson(parsed.body);
|
|
206
213
|
const styled = highlighted ? highlightCode(parsed.body, "json").join("\n") : parsed.body.split("\n").map(line => theme.fg("toolOutput", line)).join("\n");
|