@giladbarnea/pi-pretty-bash 1.0.8 → 1.0.10
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 +4 -2
- package/index.ts +19 -2
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
last_updated: 2026-11-
|
|
2
|
+
last_updated: 2026-11-14T11-33
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
<div align="center">
|
|
@@ -27,7 +27,9 @@ 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
|
-
|
|
30
|
+
Dense Bash gets readable spacing and indentation from [shfmt](https://github.com/mvdan/sh), bundled through dprint with no system binary needed. Only the display is formatted. Execution and model context keep the original command. Unparseable input stays as written.
|
|
31
|
+
|
|
32
|
+
Short commands get syntax colors in the header. Multiline formatted 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
33
|
|
|
32
34
|
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
35
|
|
package/index.ts
CHANGED
|
@@ -10,6 +10,11 @@ import {
|
|
|
10
10
|
} from "@earendil-works/pi-coding-agent";
|
|
11
11
|
import { truncateToWidth, visibleWidth, wrapTextWithAnsi, type Component } from "@earendil-works/pi-tui";
|
|
12
12
|
import { highlight } from "cli-highlight";
|
|
13
|
+
import { createFromBuffer } from "@dprint/formatter";
|
|
14
|
+
import { getBuffer } from "@dprint/shfmt";
|
|
15
|
+
|
|
16
|
+
const formatter = createFromBuffer(getBuffer());
|
|
17
|
+
formatter.setConfig({}, { dialect: "bash", useTabs: false, indentWidth: 2, binaryNextLine: true, switchCaseIndent: true, spaceRedirects: true });
|
|
13
18
|
|
|
14
19
|
const JSON_HIGHLIGHT_MAX_BYTES = 200 * 1024;
|
|
15
20
|
const PREVIEW_ROWS = 10;
|
|
@@ -110,11 +115,23 @@ function box(rows: string[], width: number, theme: Theme, caption = ""): string[
|
|
|
110
115
|
];
|
|
111
116
|
}
|
|
112
117
|
|
|
113
|
-
/**
|
|
118
|
+
/** Format display-only Bash with shfmt, leaving incomplete or unsupported syntax as written.
|
|
119
|
+
* @example formatCommand("echo one;echo two") // "echo one\necho two"
|
|
120
|
+
*/
|
|
121
|
+
function formatCommand(command: string): string {
|
|
122
|
+
try {
|
|
123
|
+
return formatter.formatText({ filePath: "display.bash", fileText: command }).replace(/\n$/, "");
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (error instanceof Error && error.constructor === Error) return command;
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Draw the command, using a numbered box for multiline formatted input; collapsed boxes hide their middle rows.
|
|
114
131
|
* @example commandRows({command: "echo hi"}, theme, false, false).render(80) // A syntax-colored Bash header.
|
|
115
132
|
*/
|
|
116
133
|
function commandRows(args: BashArguments, theme: Theme, pending: boolean, expanded: boolean): Component {
|
|
117
|
-
const command = displayText(args.command ?? "");
|
|
134
|
+
const command = displayText(formatCommand(args.command ?? ""));
|
|
118
135
|
const sourceLines = command.split("\n");
|
|
119
136
|
const highlighted = bashColors(command, theme).split("\n");
|
|
120
137
|
const firstLine = sourceLines[0].trim() || "…";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@giladbarnea/pi-pretty-bash",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Rich Bash command and result displays with syntax-colored commands and JSON output.",
|
|
6
6
|
"keywords": [
|
|
@@ -46,6 +46,8 @@
|
|
|
46
46
|
"test": "node --test test/*.test.mjs"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
+
"@dprint/formatter": "0.6.0",
|
|
50
|
+
"@dprint/shfmt": "0.2.0",
|
|
49
51
|
"cli-highlight": "2.1.11"
|
|
50
52
|
}
|
|
51
53
|
}
|