@xynogen/pix-pretty 1.36.0 → 1.37.0
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 +24 -6
- package/package.json +2 -2
- package/src/command-preview.ts +8 -4
- package/src/renderers.ts +56 -14
- package/src/shell-tool.ts +5 -2
- package/src/text.ts +12 -8
- package/src/types.ts +2 -0
- package/src/utils.ts +72 -15
package/README.md
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/xynogen/pix-mono/main/.github/assets/pix-logo.svg" alt="Pix" width="152" height="80">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# pix-pretty
|
|
2
6
|
|
|
3
7
|
Rendering and formatting library for Pi Coding Agent with syntax highlighting, file icons, tree views, FFF search integration, and gate-dialog overlay.
|
|
4
8
|
|
|
5
9
|
## What it does
|
|
6
10
|
|
|
7
|
-
This package is a
|
|
11
|
+
This package is a library and a small extension that other pix packages
|
|
8
12
|
consume. It does not register user-facing tools itself — the tool renderers
|
|
9
13
|
(`pix-read`, `pix-bash`, `pix-ls`, `pix-find`, `pix-grep`, `pix-edit`,
|
|
10
14
|
`pix-write`) import from it. The extension entry point (`src/index.ts`) only
|
|
11
|
-
|
|
15
|
+
keeps above-editor widgets in a stable order (TUI sessions), clears the highlight
|
|
12
16
|
cache, seeds the icon mode from `pix.json`, and registers two FFF slash
|
|
13
17
|
commands (`/fff-health`, `/fff-rescan`) once `pix-grep` has brought the FFF
|
|
14
18
|
finder online. The `/pix` settings command lives in `pix-runtime`.
|
|
@@ -21,12 +25,16 @@ finder online. The `/pix` settings command lives in `pix-runtime`.
|
|
|
21
25
|
- **Tree views** — hierarchical directory display for ls
|
|
22
26
|
- **Diff rendering** — side-by-side split diff for edit/write
|
|
23
27
|
- **Bash exit summary** — colored status, line count, truncation notice
|
|
28
|
+
- **Truncated previews** — a cut preview fades out bottom-up (`./text`:
|
|
29
|
+
`fadeRowsOf`) and ends with one muted footer, `… N more lines (ctrl+o to expand)`
|
|
30
|
+
(`./utils`: `moreLines`, `expandHint`). The hint shows the user's own expand
|
|
31
|
+
key through Pi's `keyHint`. Expanded views show every row.
|
|
24
32
|
|
|
25
33
|
### Icon catalog (l10n-style)
|
|
26
34
|
|
|
27
35
|
Icons are treated like a localization catalog: packages never hardcode glyph
|
|
28
|
-
codepoints — they ask for a
|
|
29
|
-
against one global icon mode. Reskinning, or fixing a missing-glyph (
|
|
36
|
+
codepoints — they ask for a semantic role and the catalog resolves it
|
|
37
|
+
against one global icon mode. Reskinning, or fixing a missing-glyph ("tofu")
|
|
30
38
|
problem on terminals without a Nerd Font, becomes a one-file edit here.
|
|
31
39
|
|
|
32
40
|
- **`./icon-catalog`** — `icon(key)` resolves a semantic key (`"cwd"`,
|
|
@@ -61,12 +69,12 @@ The one source of truth for inline chip tags. Producers build tags with `chipTag
|
|
|
61
69
|
The model receives each tag verbatim. `registerChips(pi)` shows them as chips in the prompt
|
|
62
70
|
editor and in sent user messages. `pix-display` calls it. Add a new chip kind here, not in a feature package.
|
|
63
71
|
|
|
64
|
-
UI features that moved to [`pix-display`](
|
|
72
|
+
UI features that moved to [`pix-display`](https://www.npmjs.com/package/@xynogen/pix-display): reasoning-tag (`<think>`/`<thinking>`) → native
|
|
65
73
|
`thinking` content blocks.
|
|
66
74
|
|
|
67
75
|
## Configuration
|
|
68
76
|
|
|
69
|
-
Configuration is read from
|
|
77
|
+
Configuration is read from `~/.pi/agent/pix.json` (the unified config file owned by `@xynogen/pix-runtime/config`). The `pretty` section of that file sets the defaults for theme, icon mode, and preview lines. Environment variables still override `pix.json` values.
|
|
70
78
|
|
|
71
79
|
> **Note:** config and collapse helpers previously shipped with `pix-pretty`; they now live in `pix-runtime` (`@xynogen/pix-runtime/config` and `@xynogen/pix-runtime/collapse`). Update any direct imports.
|
|
72
80
|
|
|
@@ -76,6 +84,7 @@ Configuration is read from **`~/.pi/agent/pix.json`** (the unified config file o
|
|
|
76
84
|
{
|
|
77
85
|
"pretty": {
|
|
78
86
|
"icons": "nerd", // nerd | unicode | ascii
|
|
87
|
+
"lsStyle": "grid", // grid | tree (pix-ls layout)
|
|
79
88
|
"maxPreviewLines": 80,
|
|
80
89
|
"maxRenderLines": 150,
|
|
81
90
|
"maxRenderWidth": "65%", // modal frame width; percentage or columns
|
|
@@ -95,6 +104,7 @@ Syntax highlighting, diffs, and tool surfaces use the active Pi theme. Color ove
|
|
|
95
104
|
### Environment Variables (override `pix.json`)
|
|
96
105
|
|
|
97
106
|
- `PRETTY_MAX_HL_CHARS` — max characters to highlight (default: 80000)
|
|
107
|
+
- `PRETTY_MAX_HL_LINE_CHARS` — max characters per line to highlight (default: 2000; env only)
|
|
98
108
|
- `PRETTY_MAX_PREVIEW_LINES` — max lines in preview output
|
|
99
109
|
- `PRETTY_CACHE_LIMIT` — FFF cache size limit
|
|
100
110
|
- `PRETTY_ICONS` — default icon mode when none is persisted: `nerd` (default),
|
|
@@ -111,6 +121,7 @@ The package exposes its sub-modules via `exports`:
|
|
|
111
121
|
```
|
|
112
122
|
@xynogen/pix-pretty (default — extension entry)
|
|
113
123
|
@xynogen/pix-pretty/ansi
|
|
124
|
+
@xynogen/pix-pretty/batch (multi-target `paths` helpers and section caps)
|
|
114
125
|
@xynogen/pix-pretty/confirm
|
|
115
126
|
@xynogen/pix-pretty/progress
|
|
116
127
|
@xynogen/pix-pretty/config
|
|
@@ -125,12 +136,19 @@ The package exposes its sub-modules via `exports`:
|
|
|
125
136
|
@xynogen/pix-pretty/fff
|
|
126
137
|
@xynogen/pix-pretty/types
|
|
127
138
|
@xynogen/pix-pretty/utils
|
|
139
|
+
@xynogen/pix-pretty/text (text fade helpers for previews and widgets)
|
|
140
|
+
@xynogen/pix-pretty/widget-format
|
|
128
141
|
@xynogen/pix-pretty/resize
|
|
129
142
|
@xynogen/pix-pretty/context
|
|
130
143
|
@xynogen/pix-pretty/gate-overlay
|
|
131
144
|
@xynogen/pix-pretty/modal-frame
|
|
132
145
|
@xynogen/pix-pretty/provider-picker
|
|
133
146
|
@xynogen/pix-pretty/shell-tool (shared bash/powershell tool registrar + renderer)
|
|
147
|
+
@xynogen/pix-pretty/command-preview
|
|
148
|
+
@xynogen/pix-pretty/tool-status (binary download status + missing-binary warnings)
|
|
149
|
+
@xynogen/pix-pretty/test-utils (renderer test helpers)
|
|
150
|
+
@xynogen/pix-pretty/transient-error
|
|
151
|
+
@xynogen/pix-pretty/grammar-consent
|
|
134
152
|
@xynogen/pix-pretty/chips (inline chip tags + editor/history chip renderer)
|
|
135
153
|
```
|
|
136
154
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-pretty",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.37.0",
|
|
4
4
|
"description": "Enhanced tool output rendering with syntax highlighting, file icons, tree views, diff rendering, and FFF search",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@xynogen/pix-runtime": "^0.
|
|
73
|
+
"@xynogen/pix-runtime": "^0.17.0",
|
|
74
74
|
"chalk": "^4.1.2",
|
|
75
75
|
"cli-highlight": "^2.1.11",
|
|
76
76
|
"@ff-labs/fff-node": "^0.10.6",
|
package/src/command-preview.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Text, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
2
2
|
import { hlBlock } from "./highlight.ts";
|
|
3
|
-
import { fadePaint, fadeText } from "./text.ts";
|
|
3
|
+
import { fadePaint, fadeRowsOf, fadeText } from "./text.ts";
|
|
4
4
|
import type { ThemeLike } from "./types.ts";
|
|
5
|
-
import type
|
|
5
|
+
import { type ExpandHintCtx, expandHint, type formatCollapsedToolRow } from "./utils.ts";
|
|
6
6
|
|
|
7
7
|
export function commandPreview(
|
|
8
8
|
header: string,
|
|
@@ -14,6 +14,8 @@ export function commandPreview(
|
|
|
14
14
|
expanded = false,
|
|
15
15
|
/** Body column: under the tool name (2-col status glyph + space). */
|
|
16
16
|
indent = 3,
|
|
17
|
+
/** Renderer context: the cut-off row shows the user's expand key. */
|
|
18
|
+
ctx?: ExpandHintCtx,
|
|
17
19
|
) {
|
|
18
20
|
type Slot = { code: string; language: string | undefined; theme: typeof theme; styled: string };
|
|
19
21
|
let slot = state.commandPreview as Slot | undefined;
|
|
@@ -50,12 +52,14 @@ export function commandPreview(
|
|
|
50
52
|
// ponytail: wrap without rewriting shell syntax or quoted strings. Add a shell parser only for semantic formatting.
|
|
51
53
|
const padding = " ".repeat(indent);
|
|
52
54
|
const lines = wrapTextWithAnsi(current.styled, Math.max(1, width - indent));
|
|
53
|
-
const shown = expanded ? lines : lines.slice(0, 16);
|
|
55
|
+
const shown = expanded ? lines : fadeRowsOf(lines.slice(0, 17), theme, 16);
|
|
54
56
|
return [
|
|
55
57
|
truncateToWidth(`${header}${separator}`, width, "…"),
|
|
56
58
|
...shown.map((line) => `${padding}${line}`),
|
|
57
59
|
...(shown.length < lines.length
|
|
58
|
-
? [
|
|
60
|
+
? [
|
|
61
|
+
`${theme.fg("muted", `${padding}… +${lines.length - shown.length} lines `)}${expandHint(theme, ctx)}`,
|
|
62
|
+
]
|
|
59
63
|
: []),
|
|
60
64
|
];
|
|
61
65
|
},
|
package/src/renderers.ts
CHANGED
|
@@ -7,8 +7,18 @@ import { MAX_PREVIEW_LINES } from "./config.ts";
|
|
|
7
7
|
import { hlBlock } from "./highlight.ts";
|
|
8
8
|
import { dirIcon, fileColor, fileIcon } from "./icons.ts";
|
|
9
9
|
import { lang } from "./lang.ts";
|
|
10
|
+
import { type FadeTheme, fadeRowsOf } from "./text.ts";
|
|
10
11
|
import type { FgTheme } from "./types.ts";
|
|
11
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
BODY_PAD,
|
|
14
|
+
type ExpandHintCtx,
|
|
15
|
+
expandHint,
|
|
16
|
+
lnum,
|
|
17
|
+
normalizeLineEndings,
|
|
18
|
+
pluralize,
|
|
19
|
+
rule,
|
|
20
|
+
termW,
|
|
21
|
+
} from "./utils.ts";
|
|
12
22
|
|
|
13
23
|
/** Layout controls for {@link renderFileContent}. */
|
|
14
24
|
export interface RenderFileContentOptions {
|
|
@@ -20,6 +30,8 @@ export interface RenderFileContentOptions {
|
|
|
20
30
|
* expanded views pass `true` so no source text is hidden.
|
|
21
31
|
*/
|
|
22
32
|
wrapLongLines?: boolean;
|
|
33
|
+
/** Renderer context: the overflow row shows the user's expand key. */
|
|
34
|
+
ctx?: ExpandHintCtx;
|
|
23
35
|
}
|
|
24
36
|
|
|
25
37
|
/** Render syntax-highlighted file content with line numbers. */
|
|
@@ -66,10 +78,15 @@ export async function renderFileContent(
|
|
|
66
78
|
out.push(`${lnum(ln, nw)} ${FG_RULE}│${RST} ${display}${RST}`);
|
|
67
79
|
}
|
|
68
80
|
|
|
81
|
+
// A cut preview fades its last code rows (rule row 0 stays as is).
|
|
82
|
+
if (theme && total > maxLines) out.splice(1, Infinity, ...fadeTail(out.slice(1), theme));
|
|
69
83
|
out.push(rule(tw));
|
|
70
84
|
if (total > maxLines) {
|
|
85
|
+
const more = `${BODY_PAD}… ${pluralize(total - maxLines, "more line")} (${total} total) `;
|
|
71
86
|
out.push(
|
|
72
|
-
|
|
87
|
+
theme
|
|
88
|
+
? `${theme.fg("muted", more)}${expandHint(theme, options.ctx)}`
|
|
89
|
+
: `${FG_DIM}${more}${RST}`,
|
|
73
90
|
);
|
|
74
91
|
}
|
|
75
92
|
return out.join("\n");
|
|
@@ -101,10 +118,15 @@ export function renderBashOutput(
|
|
|
101
118
|
}
|
|
102
119
|
|
|
103
120
|
/** Render ls output using the configured style (grid or tree). */
|
|
104
|
-
export function renderTree(
|
|
121
|
+
export function renderTree(
|
|
122
|
+
text: string,
|
|
123
|
+
basePath: string,
|
|
124
|
+
theme?: FgTheme,
|
|
125
|
+
ctx?: ExpandHintCtx,
|
|
126
|
+
): string {
|
|
105
127
|
return config(prettySection).lsStyle === "tree"
|
|
106
|
-
? renderLsTree(text, basePath, theme)
|
|
107
|
-
: renderLsGrid(text, basePath, theme);
|
|
128
|
+
? renderLsTree(text, basePath, theme, ctx)
|
|
129
|
+
: renderLsGrid(text, basePath, theme, ctx);
|
|
108
130
|
}
|
|
109
131
|
|
|
110
132
|
/** Vertical tree view with connectors and icons. */
|
|
@@ -115,17 +137,23 @@ function entryColor(isDir: boolean, name: string, theme?: FgTheme): string {
|
|
|
115
137
|
return isDir ? theme.fg("accent", name) : fileColor(name, name, theme);
|
|
116
138
|
}
|
|
117
139
|
|
|
118
|
-
function renderLsTree(
|
|
140
|
+
function renderLsTree(
|
|
141
|
+
text: string,
|
|
142
|
+
_basePath: string,
|
|
143
|
+
theme?: FgTheme,
|
|
144
|
+
ctx?: ExpandHintCtx,
|
|
145
|
+
): string {
|
|
119
146
|
const lines = text.trim().split("\n").filter(Boolean);
|
|
120
147
|
if (!lines.length) return `${FG_DIM}(empty directory)${RST}`;
|
|
121
148
|
|
|
122
149
|
const out: string[] = [];
|
|
123
150
|
const total = lines.length;
|
|
124
|
-
const
|
|
151
|
+
const max = ctx?.expanded ? total : MAX_PREVIEW_LINES;
|
|
152
|
+
const show = lines.slice(0, max);
|
|
125
153
|
|
|
126
154
|
for (let i = 0; i < show.length; i++) {
|
|
127
155
|
const entry = (show[i] ?? "").trim();
|
|
128
|
-
const isLast = i === show.length - 1 && total <=
|
|
156
|
+
const isLast = i === show.length - 1 && total <= max;
|
|
129
157
|
const prefix = isLast ? "└── " : "├── ";
|
|
130
158
|
const connector = `${FG_RULE}${prefix}${RST}`;
|
|
131
159
|
|
|
@@ -137,22 +165,35 @@ function renderLsTree(text: string, _basePath: string, theme?: FgTheme): string
|
|
|
137
165
|
out.push(`${connector}${icon}${displayName}`);
|
|
138
166
|
}
|
|
139
167
|
|
|
140
|
-
if (total >
|
|
168
|
+
if (theme && total > max) out.splice(0, Infinity, ...fadeTail(out, theme));
|
|
169
|
+
if (total > max) {
|
|
141
170
|
out.push(
|
|
142
|
-
`${FG_RULE}└── ${RST}${FG_DIM}… ${pluralize(total -
|
|
171
|
+
`${FG_RULE}└── ${RST}${FG_DIM}… ${pluralize(total - max, "more entry", "more entries")} ${RST}${theme ? expandHint(theme, ctx) : ""}`,
|
|
143
172
|
);
|
|
144
173
|
}
|
|
145
174
|
|
|
146
175
|
return out.join("\n");
|
|
147
176
|
}
|
|
148
177
|
|
|
178
|
+
/** Fade the last text rows of an already-cut preview (blank rows take no step). */
|
|
179
|
+
function fadeTail(rows: string[], theme: FgTheme): string[] {
|
|
180
|
+
// One sentinel row past the end tells fadeRowsOf the preview was cut.
|
|
181
|
+
return fadeRowsOf([...rows, ""], theme as FadeTheme, rows.length);
|
|
182
|
+
}
|
|
183
|
+
|
|
149
184
|
/** Horizontal grid with icons (like eza/ls). */
|
|
150
|
-
function renderLsGrid(
|
|
185
|
+
function renderLsGrid(
|
|
186
|
+
text: string,
|
|
187
|
+
_basePath: string,
|
|
188
|
+
theme?: FgTheme,
|
|
189
|
+
ctx?: ExpandHintCtx,
|
|
190
|
+
): string {
|
|
151
191
|
const lines = text.trim().split("\n").filter(Boolean);
|
|
152
192
|
if (!lines.length) return `${FG_DIM}(empty directory)${RST}`;
|
|
153
193
|
|
|
154
194
|
const total = lines.length;
|
|
155
|
-
const
|
|
195
|
+
const max = ctx?.expanded ? total : MAX_PREVIEW_LINES;
|
|
196
|
+
const show = lines.slice(0, max);
|
|
156
197
|
|
|
157
198
|
// Build styled cells + measure their visible widths
|
|
158
199
|
const cells: string[] = [];
|
|
@@ -174,9 +215,10 @@ function renderLsGrid(text: string, _basePath: string, theme?: FgTheme): string
|
|
|
174
215
|
const GAP = 3; // spaces between columns
|
|
175
216
|
const rows = layoutGrid(cells, cellWidths, tw, GAP);
|
|
176
217
|
|
|
177
|
-
if (total >
|
|
218
|
+
if (theme && total > max) rows.splice(0, Infinity, ...fadeTail(rows, theme));
|
|
219
|
+
if (total > max) {
|
|
178
220
|
rows.push(
|
|
179
|
-
`${FG_DIM}… ${pluralize(total -
|
|
221
|
+
`${FG_DIM}… ${pluralize(total - max, "more entry", "more entries")} ${RST}${theme ? expandHint(theme, ctx) : ""}`,
|
|
180
222
|
);
|
|
181
223
|
}
|
|
182
224
|
|
package/src/shell-tool.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
BODY_PAD,
|
|
29
29
|
bodyLine,
|
|
30
30
|
dotJoin,
|
|
31
|
+
fadeRulePaint,
|
|
31
32
|
fillToolBackground,
|
|
32
33
|
formatCollapsedToolRow,
|
|
33
34
|
formatToolCallTitle,
|
|
@@ -163,6 +164,7 @@ export function registerShellTool(
|
|
|
163
164
|
renderCtx.invalidate,
|
|
164
165
|
renderCtx.expanded,
|
|
165
166
|
3,
|
|
167
|
+
renderCtx,
|
|
166
168
|
);
|
|
167
169
|
},
|
|
168
170
|
|
|
@@ -227,13 +229,14 @@ export function registerShellTool(
|
|
|
227
229
|
}
|
|
228
230
|
|
|
229
231
|
const maxShow = renderCtx.expanded ? lineCount : MAX_PREVIEW_LINES;
|
|
230
|
-
const footer =
|
|
232
|
+
const footer =
|
|
233
|
+
lineCount > maxShow ? [moreLines(lineCount - maxShow, theme, renderCtx)] : [];
|
|
231
234
|
// Every result (including single-line) is framed; the rules follow exit
|
|
232
235
|
// status: green ok, red failure. The `✓ exit N` header is dropped — the
|
|
233
236
|
// collapsed row already carries status.
|
|
234
237
|
const exitCode = d.exitCode as number | null;
|
|
235
238
|
const statusKey = exitCode === null || exitCode === 0 ? "success" : "error";
|
|
236
|
-
const paint = (
|
|
239
|
+
const paint = fadeRulePaint(theme, statusKey);
|
|
237
240
|
// Fade the last preview rows instead of a hard cut before the "… N more" row.
|
|
238
241
|
const body = fadeRowsOf(
|
|
239
242
|
lines.slice(0, maxShow + 1).map((line) => bodyLine(line, theme)),
|
package/src/text.ts
CHANGED
|
@@ -129,6 +129,8 @@ export function fadeTextRow(
|
|
|
129
129
|
* `maxLines` rows, the last `fadeRows` of them fading. Returns all rows unchanged when
|
|
130
130
|
* they fit, so `fadeRowsOf(lines, theme, expanded ? Infinity : MAX)` replaces
|
|
131
131
|
* `lines.slice(0, max)`. The caller adds its own "… N more" / hint row.
|
|
132
|
+
*
|
|
133
|
+
* Blank rows never take a fade step: the steps go to the last rows with text.
|
|
132
134
|
*/
|
|
133
135
|
export function fadeRowsOf(
|
|
134
136
|
lines: string[],
|
|
@@ -140,13 +142,15 @@ export function fadeRowsOf(
|
|
|
140
142
|
const paint = fadePaint(theme);
|
|
141
143
|
// At most a third of the preview fades, so short previews stay readable.
|
|
142
144
|
const rows = Math.min(fadeRows, Math.floor(maxLines / 3));
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const plain = stripTerminalSequences(line);
|
|
145
|
+
const shown = lines.slice(0, maxLines);
|
|
146
|
+
// Walk up from the bottom: the last text row is faintest, blank rows are skipped.
|
|
147
|
+
for (let i = shown.length - 1, step = rows; i >= 0 && step > 0; i--) {
|
|
148
|
+
const plain = stripTerminalSequences(shown[i] ?? "");
|
|
148
149
|
const text = plain.trimStart();
|
|
149
|
-
if (!text)
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
if (!text) continue;
|
|
151
|
+
// Keep leading padding uncolored; stop at 0.85 so the last row stays faintly readable.
|
|
152
|
+
shown[i] = plain.slice(0, plain.length - text.length) + paint(text, (step / (rows + 1)) * 0.85);
|
|
153
|
+
step--;
|
|
154
|
+
}
|
|
155
|
+
return shown;
|
|
152
156
|
}
|
package/src/types.ts
CHANGED
|
@@ -74,6 +74,8 @@ export type RenderContextLike<
|
|
|
74
74
|
toolCallId?: string;
|
|
75
75
|
/** Host-recorded execution time of the final result (Pi >= 1.1). Undefined while partial. */
|
|
76
76
|
durationMs?: number;
|
|
77
|
+
/** Host-styled `<keys> <description>` for a keybinding (Pi >= 1.5). Use for the expand hint. */
|
|
78
|
+
keyHint?: (keybinding: "app.tools.expand", description: string) => string;
|
|
77
79
|
};
|
|
78
80
|
|
|
79
81
|
type SessionContextLike = ExtensionContext;
|
package/src/utils.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isAbsolute, relative, resolve } from "node:path";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import {
|
|
4
|
+
type Color,
|
|
4
5
|
type Component,
|
|
5
6
|
getCapabilities,
|
|
6
7
|
hyperlink,
|
|
7
8
|
MouseRegion,
|
|
8
|
-
|
|
9
|
+
mixColors,
|
|
9
10
|
truncateToWidth,
|
|
10
11
|
visibleWidth,
|
|
11
12
|
} from "@earendil-works/pi-tui";
|
|
@@ -90,9 +91,7 @@ type ResultComponent = ViewportComponent & {
|
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
type FramableComponent = Partial<ResultComponent> & Partial<TextComponentLike>;
|
|
93
|
-
type ResultFrameTheme =
|
|
94
|
-
fg: (key: "success" | "error", text: string) => string;
|
|
95
|
-
};
|
|
94
|
+
type ResultFrameTheme = StatusRuleTheme;
|
|
96
95
|
|
|
97
96
|
const RESULT_FRAME = Symbol("pix.resultFrame");
|
|
98
97
|
type FramedResultComponent = ResultComponent & {
|
|
@@ -445,6 +444,8 @@ export type DimPreviewOptions = {
|
|
|
445
444
|
frame?: boolean;
|
|
446
445
|
/** Tint the frame rules (green ok, red error) — same status color as bash/ls. */
|
|
447
446
|
paint?: RulePaint;
|
|
447
|
+
/** Renderer context: the overflow row shows the user's expand key. */
|
|
448
|
+
ctx?: ExpandHintCtx;
|
|
448
449
|
};
|
|
449
450
|
|
|
450
451
|
/** Compile a highlight pattern into a global RegExp, or null when it can't
|
|
@@ -517,7 +518,8 @@ export function renderDimPreview(
|
|
|
517
518
|
maxLines,
|
|
518
519
|
);
|
|
519
520
|
const header = opts.header ? `${BODY_PAD}${theme.fg("dim", opts.header)}` : undefined;
|
|
520
|
-
const overflow =
|
|
521
|
+
const overflow =
|
|
522
|
+
lines.length > maxLines ? moreLines(lines.length - maxLines, theme, opts.ctx) : undefined;
|
|
521
523
|
|
|
522
524
|
if (opts.frame) {
|
|
523
525
|
// One shape regardless of line count: a single framed box, no floating
|
|
@@ -619,14 +621,49 @@ export function linkedShortPath(cwd: string, home: string, p: string): string {
|
|
|
619
621
|
/** Paints a rule line. Callers pass `(s) => theme.fg(status, s)` so the frame
|
|
620
622
|
* tint follows the active theme (success/error/warning). Default = neutral FG_RULE. */
|
|
621
623
|
export type RulePaint = (glyphs: string) => string;
|
|
622
|
-
export type RuleStyle = "solid" | "dashed";
|
|
623
624
|
|
|
624
|
-
/** Render a full-width solid rule
|
|
625
|
-
export function rule(w: number, paint?: RulePaint
|
|
626
|
-
const glyphs =
|
|
625
|
+
/** Render a full-width solid rule. */
|
|
626
|
+
export function rule(w: number, paint?: RulePaint): string {
|
|
627
|
+
const glyphs = "─".repeat(w);
|
|
627
628
|
return paint ? paint(glyphs) : `${FG_RULE}${glyphs}${RST}`;
|
|
628
629
|
}
|
|
629
630
|
|
|
631
|
+
/** Theme slice for {@link fadeRulePaint}. Without `colors`/`style` the rule stays flat. */
|
|
632
|
+
export type StatusRuleTheme = {
|
|
633
|
+
fg: (key: "success" | "error", text: string) => string;
|
|
634
|
+
colors?: Readonly<Record<string, Color | undefined>>;
|
|
635
|
+
style?: (text: string, style: { fg: Color }) => string;
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Status-colored rule paint that fades in on the left and out on the right: the last
|
|
640
|
+
* `fadeColumns` cells at each end mix toward the tool background. Themes without color
|
|
641
|
+
* data get the plain `theme.fg(role, …)` rule.
|
|
642
|
+
*/
|
|
643
|
+
export function fadeRulePaint(
|
|
644
|
+
theme: StatusRuleTheme,
|
|
645
|
+
role: "success" | "error",
|
|
646
|
+
fadeColumns = 8,
|
|
647
|
+
): RulePaint {
|
|
648
|
+
return (glyphs) => {
|
|
649
|
+
const cells = [...glyphs];
|
|
650
|
+
const edge = Math.min(fadeColumns, Math.floor(cells.length / 2));
|
|
651
|
+
const fg = theme.colors?.[role];
|
|
652
|
+
const bg = theme.colors?.[role === "error" ? "toolErrorBg" : "toolSuccessBg"];
|
|
653
|
+
if (!fg || !bg || !theme.style || edge < 1) return theme.fg(role, glyphs);
|
|
654
|
+
// Cell i from the edge (0 = outermost) is faintest at the edge, full color past `edge`.
|
|
655
|
+
// Call as a method: Pi's Theme.style reads `this`.
|
|
656
|
+
const cell = (ch: string, i: number) =>
|
|
657
|
+
theme.style?.(ch, { fg: mixColors(fg, bg, 1 - (i + 1) / (edge + 1)) }) ?? ch;
|
|
658
|
+
const left = cells.slice(0, edge).map(cell).join("");
|
|
659
|
+
const right = cells
|
|
660
|
+
.slice(-edge)
|
|
661
|
+
.map((ch, i) => cell(ch, edge - 1 - i))
|
|
662
|
+
.join("");
|
|
663
|
+
return left + theme.fg(role, cells.slice(edge, -edge).join("")) + right;
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
|
|
630
667
|
/** Narrow theme for helpers that paint only `muted`. Pi's Theme and FgTheme both fit. */
|
|
631
668
|
type MutedTheme = { fg: (key: "muted", text: string) => string };
|
|
632
669
|
|
|
@@ -697,9 +734,29 @@ export function bodyLine(
|
|
|
697
734
|
return `${BODY_PAD}${sectionRule(line, theme, termW() - 3) ?? paint(line)}`;
|
|
698
735
|
}
|
|
699
736
|
|
|
700
|
-
/**
|
|
701
|
-
export
|
|
702
|
-
|
|
737
|
+
/** Renderer context slice that knows the user's expand key (Pi's `ToolRenderContext`). */
|
|
738
|
+
export type ExpandHintCtx = {
|
|
739
|
+
keyHint?: (keybinding: "app.tools.expand", description: string) => string;
|
|
740
|
+
/** Expanded view: renderers that take this context show every row, no hint. */
|
|
741
|
+
expanded?: boolean;
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* `(ctrl+o to expand)` with the user's configured key, styled like Pi's own hint.
|
|
746
|
+
* Without a host `keyHint` (tests, old hosts), the key falls back to `ctrl+o`.
|
|
747
|
+
*/
|
|
748
|
+
export function expandHint(theme: MutedTheme, ctx?: ExpandHintCtx): string {
|
|
749
|
+
const hint =
|
|
750
|
+
ctx?.keyHint?.("app.tools.expand", "to expand") ?? theme.fg("muted", "ctrl+o to expand");
|
|
751
|
+
return `${theme.fg("muted", "(")}${hint}${theme.fg("muted", ")")}`;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Muted `… N more lines (ctrl+o to expand)` footer for a truncated tool-result body.
|
|
756
|
+
* Pass the renderer context so the hint shows the user's own expand key.
|
|
757
|
+
*/
|
|
758
|
+
export function moreLines(count: number, theme: MutedTheme, ctx?: ExpandHintCtx): string {
|
|
759
|
+
return `${BODY_PAD}${theme.fg("muted", `… ${pluralize(count, "more line")} `)}${expandHint(theme, ctx)}`;
|
|
703
760
|
}
|
|
704
761
|
|
|
705
762
|
/** Decorate completed tool output with status-colored default chrome. */
|
|
@@ -755,7 +812,7 @@ function decorateToolResult(
|
|
|
755
812
|
},
|
|
756
813
|
wantsKeyRelease: component.wantsKeyRelease,
|
|
757
814
|
render(width) {
|
|
758
|
-
const paint = (
|
|
815
|
+
const paint = fadeRulePaint(frameTheme, failed ? "error" : "success");
|
|
759
816
|
const lines = component.render?.(width) ?? [];
|
|
760
817
|
return solid ? sectionFrame(lines, [], width, paint) : ruleFrame(lines, [], width, paint);
|
|
761
818
|
},
|
|
@@ -776,7 +833,7 @@ export function unframeToolResult<T extends FramableComponent>(component: T): T
|
|
|
776
833
|
}
|
|
777
834
|
|
|
778
835
|
/**
|
|
779
|
-
* Default completed-tool chrome: unchanged body, full-width
|
|
836
|
+
* Default completed-tool chrome: unchanged body, full-width solid close, then
|
|
780
837
|
* footer lines. Existing callers inherit this distro-wide presentation.
|
|
781
838
|
*/
|
|
782
839
|
export function ruleFrame(
|
|
@@ -785,7 +842,7 @@ export function ruleFrame(
|
|
|
785
842
|
width?: number,
|
|
786
843
|
paint?: RulePaint,
|
|
787
844
|
): string[] {
|
|
788
|
-
return [...bodyLines, rule(width ?? termW(), paint
|
|
845
|
+
return [...bodyLines, rule(width ?? termW(), paint), ...footerLines];
|
|
789
846
|
}
|
|
790
847
|
|
|
791
848
|
/** Explicit solid top/bottom frame for sections that need stronger separation. */
|