@xynogen/pix-pretty 3.2.0 → 3.4.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/package.json +1 -1
- package/src/diff-render.ts +5 -3
- package/src/frame.ts +149 -12
- package/src/render-row.ts +4 -3
- package/src/renderers.ts +23 -18
- package/src/shell-tool.ts +6 -6
- package/src/tool-card.ts +5 -2
- package/src/utils.ts +12 -1
package/package.json
CHANGED
package/src/diff-render.ts
CHANGED
|
@@ -12,7 +12,7 @@ import * as Diff from "diff";
|
|
|
12
12
|
import { BG_BASE, BOLD, FG_DIM, FG_GREEN, FG_LNUM, FG_RED, FG_RULE, RST } from "./ansi.ts";
|
|
13
13
|
import { MAX_HL_CHARS, MAX_RENDER_LINES, WORD_DIFF_MIN_SIM } from "./config.ts";
|
|
14
14
|
import type { DiffLine, ParsedDiff } from "./diff.ts";
|
|
15
|
-
import {
|
|
15
|
+
import { bodyLine } from "./frame.ts";
|
|
16
16
|
import { hlBlock } from "./highlight.ts";
|
|
17
17
|
import type { BundledLanguage, FgTheme } from "./types.ts";
|
|
18
18
|
import { terminalWidth } from "./utils.ts";
|
|
@@ -669,7 +669,9 @@ export async function renderUnified(
|
|
|
669
669
|
|
|
670
670
|
out.push(rule(tw));
|
|
671
671
|
if (diff.lines.length > vis.length) {
|
|
672
|
-
out.push(
|
|
672
|
+
out.push(
|
|
673
|
+
`${BG_BASE}${bodyLine(`${FG_DIM}… ${diff.lines.length - vis.length} more lines${RST}`)}`,
|
|
674
|
+
);
|
|
673
675
|
}
|
|
674
676
|
return out.join("\n");
|
|
675
677
|
}
|
|
@@ -851,7 +853,7 @@ export async function renderSplit(
|
|
|
851
853
|
|
|
852
854
|
out.push(`${rule(half)}${FG_RULE}┊${RST}${rule(half)}`);
|
|
853
855
|
if (rows.length > vis.length) {
|
|
854
|
-
out.push(`${BG_BASE}${FG_DIM}
|
|
856
|
+
out.push(`${BG_BASE}${bodyLine(`${FG_DIM}… ${rows.length - vis.length} more lines${RST}`)}`);
|
|
855
857
|
}
|
|
856
858
|
return out.join("\n");
|
|
857
859
|
}
|
package/src/frame.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type Color,
|
|
3
|
+
type Component,
|
|
4
|
+
mixColors,
|
|
5
|
+
Text,
|
|
6
|
+
visibleWidth,
|
|
7
|
+
wrapTextWithAnsi,
|
|
8
|
+
} from "@earendil-works/pi-tui";
|
|
2
9
|
import { FG_RULE, hasAnsi, RST } from "./ansi.ts";
|
|
3
10
|
import { MAX_PREVIEW_LINES } from "./config.ts";
|
|
4
11
|
import { fadeRowsOf, pluralize } from "./text.ts";
|
|
@@ -96,22 +103,139 @@ export function sectionRule(line: string, theme: MutedTheme, width: number): str
|
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
106
|
+
* The tool-result body column: 3 cells, the title column after the 2-cell status icon and a
|
|
107
|
+
* space. Spaces, not a tab, so `Text` rows and raw component rows land in the same column.
|
|
108
|
+
* Plugins never interpolate it: use `bodyLine`, `bodyText`, `bodyBlock`, `bodyRows`,
|
|
109
|
+
* `glyphBody` or `bodyColumn` (`scripts/deps.test.ts` enforces this).
|
|
101
110
|
*/
|
|
102
|
-
export const BODY_PAD = "
|
|
111
|
+
export const BODY_PAD = " ";
|
|
112
|
+
|
|
113
|
+
/** Room for content in the body column of a terminal-wide card. */
|
|
114
|
+
export const bodyWidth = (): number => Math.max(1, terminalWidth() - BODY_PAD.length);
|
|
103
115
|
|
|
104
116
|
/**
|
|
105
|
-
* One tool-result body line, aligned under the tool title.
|
|
106
|
-
* becomes a full-width section rule. Other lines go
|
|
117
|
+
* One tool-result body line, aligned under the tool title. With a theme, an `=== label ===`
|
|
118
|
+
* line becomes a full-width section rule; without one the line is kept as is. Other lines go
|
|
119
|
+
* through `paint`. Does not wrap: use it for rows that map 1:1 to source lines (fading
|
|
120
|
+
* previews, pre-styled renderer rows); otherwise use `bodyText`.
|
|
107
121
|
*/
|
|
108
122
|
export function bodyLine(
|
|
109
123
|
line: string,
|
|
110
|
-
theme
|
|
124
|
+
theme?: MutedTheme,
|
|
111
125
|
paint: (line: string) => string = (s) => s,
|
|
112
126
|
): string {
|
|
113
|
-
|
|
114
|
-
return `${BODY_PAD}${
|
|
127
|
+
const rule = theme && sectionRule(line, theme, bodyWidth());
|
|
128
|
+
return `${BODY_PAD}${rule ?? paint(line)}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Leading escape codes, then the row's own indent. */
|
|
132
|
+
const LEAD = /^((?:\x1b\[[0-9;]*m)*)([ \t]*)/;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* How far continuation rows hang past a line's own indent: a fixed count, or a function of
|
|
136
|
+
* that indent's width (e.g. `(indent) => (indent ? 2 : 0)` hangs only nested lines).
|
|
137
|
+
*/
|
|
138
|
+
export type Hang = number | ((indent: number) => number);
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Wrap `text` to `width`. Each row keeps its own leading indent, so a nested row never
|
|
142
|
+
* wraps back to column 0; continuation rows hang `hang` cells deeper. A color opened on one
|
|
143
|
+
* line carries to the next (`theme.fg("error", "a\nb")` paints both rows).
|
|
144
|
+
*/
|
|
145
|
+
export function wrapUnderIndent(text: string, width: number, hang: Hang = 0): string[] {
|
|
146
|
+
// An unbounded width splits on `\n` only; pi-tui re-opens the active codes on each line.
|
|
147
|
+
return wrapTextWithAnsi(text, Number.MAX_SAFE_INTEGER).flatMap((line) => {
|
|
148
|
+
const [, codes = "", pad = ""] = LEAD.exec(line) ?? [];
|
|
149
|
+
const rest = codes + line.slice(codes.length + pad.length);
|
|
150
|
+
const indent = visibleWidth(pad);
|
|
151
|
+
const deeper = pad + " ".repeat(typeof hang === "number" ? hang : hang(indent));
|
|
152
|
+
const room = Math.max(10, width - visibleWidth(deeper));
|
|
153
|
+
return wrapTextWithAnsi(rest, room).map((row, i) => (i === 0 ? pad : deeper) + row);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* A whole tool-result body as a string, for `Text` components: every row in the body column,
|
|
159
|
+
* wrapped at terminal width under its own indent. A narrower render width re-wraps without
|
|
160
|
+
* the indent; for a body whose card can be narrower than the terminal use `bodyBlock`.
|
|
161
|
+
*/
|
|
162
|
+
export function bodyText(text: string, theme: MutedTheme, hang: Hang = 0): string {
|
|
163
|
+
return wrapUnderIndent(text, bodyWidth(), hang)
|
|
164
|
+
.map((row) => (visibleWidth(row) ? bodyLine(row, theme) : row))
|
|
165
|
+
.join("\n");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
type BodyComponent = { render(width: number): string[]; invalidate(): void };
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Indent a component into the body column: it renders at the width minus the indent, and
|
|
172
|
+
* every row it returns is indented. Its own wrapping or clipping stays in the column.
|
|
173
|
+
*/
|
|
174
|
+
export function bodyColumn(inner: {
|
|
175
|
+
render(width: number): readonly string[];
|
|
176
|
+
invalidate(): void;
|
|
177
|
+
}): BodyComponent {
|
|
178
|
+
return {
|
|
179
|
+
render: (width) =>
|
|
180
|
+
inner.render(Math.max(1, width - BODY_PAD.length)).map((row) => BODY_PAD + row),
|
|
181
|
+
invalidate: () => inner.invalidate(),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* A whole tool-result body as a component: like `bodyText`, but it wraps at the render width,
|
|
187
|
+
* so it holds at any card width. `hang` indents continuation rows.
|
|
188
|
+
*/
|
|
189
|
+
export function bodyBlock(text: string, hang: Hang = 0): BodyComponent {
|
|
190
|
+
return bodyRows(() => [text], hang);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* A body built at render time from parts: plain content (put in the body column) or an
|
|
195
|
+
* already-indented `Body` (a `renderDimPreview`, a nested block). Nothing is indented twice
|
|
196
|
+
* and nothing wraps back to column 0. `build` gets the body width (the card width minus the
|
|
197
|
+
* body indent), the room a plain part has.
|
|
198
|
+
*/
|
|
199
|
+
export function bodyRows(
|
|
200
|
+
build: (bodyWidth: number) => readonly (string | Body | false | null | undefined)[],
|
|
201
|
+
hang: Hang = 0,
|
|
202
|
+
): BodyComponent {
|
|
203
|
+
return {
|
|
204
|
+
render: (width) =>
|
|
205
|
+
build(Math.max(1, width - BODY_PAD.length))
|
|
206
|
+
.flatMap((part) => {
|
|
207
|
+
if (!part && part !== "") return [];
|
|
208
|
+
// An indented part already sits in the column: re-wrap it under its own indent.
|
|
209
|
+
if (typeof part !== "string") return wrapUnderIndent(part.text, width, hang);
|
|
210
|
+
return wrapUnderIndent(part, width - BODY_PAD.length, hang).map((row) =>
|
|
211
|
+
visibleWidth(row) ? BODY_PAD + row : row,
|
|
212
|
+
);
|
|
213
|
+
})
|
|
214
|
+
// Full-width rows, like `Text`, so the card background fills the line.
|
|
215
|
+
.map((row) => row + " ".repeat(Math.max(0, width - visibleWidth(row)))),
|
|
216
|
+
invalidate() {},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Content that already sits in the body column, so `bodyRows` keeps it as is. */
|
|
221
|
+
export type Body = { readonly text: string };
|
|
222
|
+
|
|
223
|
+
/** Mark text that already carries the body indent (e.g. a `renderDimPreview`). */
|
|
224
|
+
export const indented = (text: string): Body => ({ text });
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* A body led by a status glyph: the glyph (padded to 2 cells) and a space take the first
|
|
228
|
+
* row's indent; every other row sits in the body column under it. `glyph` is painted.
|
|
229
|
+
*/
|
|
230
|
+
export function glyphBody(glyph: string, text: string): BodyComponent {
|
|
231
|
+
const lead = `${glyph}${" ".repeat(Math.max(1, BODY_PAD.length - visibleWidth(glyph)))}`;
|
|
232
|
+
return {
|
|
233
|
+
render: (width) =>
|
|
234
|
+
wrapUnderIndent(text, width - BODY_PAD.length).map(
|
|
235
|
+
(row, i) => (i === 0 ? lead : BODY_PAD) + row,
|
|
236
|
+
),
|
|
237
|
+
invalidate() {},
|
|
238
|
+
};
|
|
115
239
|
}
|
|
116
240
|
|
|
117
241
|
/** Renderer context slice that knows the user's expand key (Pi's `ToolRenderContext`). */
|
|
@@ -132,11 +256,24 @@ export function expandHint(theme: MutedTheme, ctx?: ExpandHintCtx): string {
|
|
|
132
256
|
}
|
|
133
257
|
|
|
134
258
|
/**
|
|
135
|
-
* Muted `… N more
|
|
136
|
-
*
|
|
259
|
+
* Muted `… N more <noun>s (ctrl+o to expand)` footer text for a truncated body. Unindented:
|
|
260
|
+
* put it in the body with the rest of the content. `noun` carries its own qualifier
|
|
261
|
+
* (`"more line"`, `"earlier line"`). Pass the renderer context so the hint shows the user's
|
|
262
|
+
* own expand key.
|
|
137
263
|
*/
|
|
264
|
+
export function moreText(
|
|
265
|
+
count: number,
|
|
266
|
+
noun: string,
|
|
267
|
+
theme: MutedTheme,
|
|
268
|
+
ctx?: ExpandHintCtx,
|
|
269
|
+
plural?: string,
|
|
270
|
+
): string {
|
|
271
|
+
return `${theme.fg("muted", `… ${pluralize(count, noun, plural)} `)}${expandHint(theme, ctx)}`;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** `moreText` for lines, as a finished body row (for row-by-row previews). */
|
|
138
275
|
export function moreLines(count: number, theme: MutedTheme, ctx?: ExpandHintCtx): string {
|
|
139
|
-
return `${BODY_PAD}${
|
|
276
|
+
return `${BODY_PAD}${moreText(count, "more line", theme, ctx)}`;
|
|
140
277
|
}
|
|
141
278
|
|
|
142
279
|
/** Decorate completed tool output with status-colored default chrome. */
|
package/src/render-row.ts
CHANGED
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
import { BG_BASE, BG_ERROR, BOLD, BOLD_OFF, hasAnsi } from "./ansi.ts";
|
|
10
10
|
import { MAX_PREVIEW_LINES } from "./config.ts";
|
|
11
11
|
import {
|
|
12
|
-
BODY_PAD,
|
|
13
12
|
bodyLine,
|
|
13
|
+
bodyText,
|
|
14
14
|
type ExpandHintCtx,
|
|
15
15
|
moreLines,
|
|
16
16
|
type RulePaint,
|
|
@@ -21,8 +21,9 @@ import { icon } from "./icon-catalog.ts";
|
|
|
21
21
|
import { fadeLine, fadePaint, fadeRowsOf, fadeText, normalizeLineEndings } from "./text.ts";
|
|
22
22
|
import type { FgTheme } from "./types.ts";
|
|
23
23
|
import { fillToolBackground, terminalWidth } from "./utils.ts";
|
|
24
|
+
/** A tool's error text as a result body: indented under the title, every row painted red. */
|
|
24
25
|
export function renderToolError(error: string, theme: FgTheme): string {
|
|
25
|
-
return fillToolBackground(theme.fg("error", error), BG_ERROR);
|
|
26
|
+
return fillToolBackground(bodyText(theme.fg("error", error), theme), BG_ERROR);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export type CollapsedToolStatus = "success" | "error" | "warning";
|
|
@@ -314,7 +315,7 @@ export function renderDimPreview(
|
|
|
314
315
|
theme,
|
|
315
316
|
maxLines,
|
|
316
317
|
);
|
|
317
|
-
const header = opts.header ?
|
|
318
|
+
const header = opts.header ? bodyLine(theme.fg("dim", opts.header), theme) : undefined;
|
|
318
319
|
const overflow =
|
|
319
320
|
lines.length > maxLines ? moreLines(lines.length - maxLines, theme, opts.ctx) : undefined;
|
|
320
321
|
|
package/src/renderers.ts
CHANGED
|
@@ -2,15 +2,15 @@ import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works
|
|
|
2
2
|
import { config } from "@xynogen/pix-runtime/config";
|
|
3
3
|
import { prettySection } from "@xynogen/pix-runtime/sections";
|
|
4
4
|
|
|
5
|
-
import { FG_DIM,
|
|
5
|
+
import { FG_DIM, FG_RULE, RST } from "./ansi.ts";
|
|
6
6
|
import { MAX_PREVIEW_LINES } from "./config.ts";
|
|
7
|
-
import {
|
|
7
|
+
import { bodyLine, bodyWidth, type ExpandHintCtx, expandHint, rule } from "./frame.ts";
|
|
8
8
|
import { hlBlock } from "./highlight.ts";
|
|
9
9
|
import { dirIcon, fileColor, fileIcon } from "./icons.ts";
|
|
10
10
|
import { lang } from "./lang.ts";
|
|
11
11
|
import { type FadeTheme, fadeRowsOf, normalizeLineEndings, pluralize } from "./text.ts";
|
|
12
12
|
import type { FgTheme } from "./types.ts";
|
|
13
|
-
import {
|
|
13
|
+
import { gutterWidth, lineGutter, terminalWidth } from "./utils.ts";
|
|
14
14
|
|
|
15
15
|
/** Layout controls for {@link renderFileContent}. */
|
|
16
16
|
export interface RenderFileContentOptions {
|
|
@@ -49,7 +49,7 @@ export async function renderFileContent(
|
|
|
49
49
|
const startLine = offset;
|
|
50
50
|
const endLine = startLine + show.length - 1;
|
|
51
51
|
const nw = Math.max(3, String(endLine).length);
|
|
52
|
-
const gw = nw
|
|
52
|
+
const gw = gutterWidth(nw);
|
|
53
53
|
const cw = Math.max(1, tw - gw);
|
|
54
54
|
|
|
55
55
|
const out: string[] = [];
|
|
@@ -62,24 +62,24 @@ export async function renderFileContent(
|
|
|
62
62
|
// Expanded view: no tail is hidden. First row carries the line number,
|
|
63
63
|
// continuation rows indent under the gutter so the code column aligns.
|
|
64
64
|
const rows = wrapTextWithAnsi(code, cw);
|
|
65
|
-
const pad = " ".repeat(nw);
|
|
66
65
|
rows.forEach((rowText, r) => {
|
|
67
|
-
|
|
68
|
-
out.push(`${gutter} ${FG_RULE}│${RST} ${rowText}${RST}`);
|
|
66
|
+
out.push(`${lineGutter(r === 0 ? ln : "", nw)}${rowText}${RST}`);
|
|
69
67
|
});
|
|
70
68
|
continue;
|
|
71
69
|
}
|
|
72
70
|
const display = truncateToWidth(code, cw, `${FG_DIM}›`);
|
|
73
|
-
out.push(`${
|
|
71
|
+
out.push(`${lineGutter(ln, nw)}${display}${RST}`);
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
out.push(rule(tw));
|
|
77
75
|
if (total > maxLines) {
|
|
78
|
-
const more =
|
|
76
|
+
const more = `… ${pluralize(total - maxLines, "more line")} (${total} total) `;
|
|
79
77
|
out.push(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
bodyLine(
|
|
79
|
+
theme
|
|
80
|
+
? `${theme.fg("muted", more)}${expandHint(theme, options.ctx)}`
|
|
81
|
+
: `${FG_DIM}${more}${RST}`,
|
|
82
|
+
),
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
return out.join("\n");
|
|
@@ -110,16 +110,21 @@ export function renderBashOutput(
|
|
|
110
110
|
return { summary: codeStr, body };
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
/** Render ls output using the configured style (grid or tree). */
|
|
113
|
+
/** Render ls output using the configured style (grid or tree), in the body column. */
|
|
114
114
|
export function renderTree(
|
|
115
115
|
text: string,
|
|
116
116
|
basePath: string,
|
|
117
117
|
theme?: FgTheme,
|
|
118
118
|
ctx?: ExpandHintCtx,
|
|
119
119
|
): string {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
const out =
|
|
121
|
+
config(prettySection).lsStyle === "tree"
|
|
122
|
+
? renderLsTree(text, basePath, theme, ctx)
|
|
123
|
+
: renderLsGrid(text, basePath, theme, ctx);
|
|
124
|
+
return out
|
|
125
|
+
.split("\n")
|
|
126
|
+
.map((row) => bodyLine(row))
|
|
127
|
+
.join("\n");
|
|
123
128
|
}
|
|
124
129
|
|
|
125
130
|
/** Vertical tree view with connectors and icons. */
|
|
@@ -201,8 +206,8 @@ function renderLsGrid(
|
|
|
201
206
|
cellWidths.push(visibleWidth(cell));
|
|
202
207
|
}
|
|
203
208
|
|
|
204
|
-
// Layout into columns that fit the terminal width
|
|
205
|
-
const tw =
|
|
209
|
+
// Layout into columns that fit the terminal width, minus the body indent renderTree adds.
|
|
210
|
+
const tw = bodyWidth();
|
|
206
211
|
const GAP = 3; // spaces between columns
|
|
207
212
|
const rows = layoutGrid(cells, cellWidths, tw, GAP);
|
|
208
213
|
|
package/src/shell-tool.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { type CollapseState, tickCollapse } from "@xynogen/pix-runtime/collapse"
|
|
|
13
13
|
import { getErrorMessage } from "@xynogen/pix-runtime/errors";
|
|
14
14
|
import { resolveBaseBackground } from "./ansi.ts";
|
|
15
15
|
import { collapsedCommandRow, commandPreview } from "./command-preview.ts";
|
|
16
|
-
import {
|
|
16
|
+
import { bodyLine, bodyText, frameToolResult, outputBodyRows, reuseText } from "./frame.ts";
|
|
17
17
|
import {
|
|
18
18
|
dotJoin,
|
|
19
19
|
hideCollapsedToolCall,
|
|
@@ -196,7 +196,7 @@ export function registerShellTool(
|
|
|
196
196
|
theme,
|
|
197
197
|
);
|
|
198
198
|
} else {
|
|
199
|
-
text.setText(fillToolBackground(
|
|
199
|
+
text.setText(fillToolBackground(bodyLine(theme.fg("muted", "done"), theme)));
|
|
200
200
|
}
|
|
201
201
|
return text;
|
|
202
202
|
}
|
|
@@ -238,7 +238,7 @@ export function registerShellTool(
|
|
|
238
238
|
return text;
|
|
239
239
|
}
|
|
240
240
|
text.setText(
|
|
241
|
-
fillToolBackground(
|
|
241
|
+
fillToolBackground(bodyText(theme.fg("dim", String(fallbackText).slice(0, 120)), theme)),
|
|
242
242
|
);
|
|
243
243
|
return completed();
|
|
244
244
|
},
|
|
@@ -355,7 +355,7 @@ export function renderGatedCommandResult(
|
|
|
355
355
|
|
|
356
356
|
if (running) {
|
|
357
357
|
text.setText(
|
|
358
|
-
fillToolBackground(
|
|
358
|
+
fillToolBackground(bodyText(theme.fg("muted", getTextContent(result) || "working"), theme)),
|
|
359
359
|
);
|
|
360
360
|
return text;
|
|
361
361
|
}
|
|
@@ -365,7 +365,7 @@ export function renderGatedCommandResult(
|
|
|
365
365
|
text.setText(
|
|
366
366
|
details.outcome === "error"
|
|
367
367
|
? renderToolError(diagnostic, theme)
|
|
368
|
-
: fillToolBackground(
|
|
368
|
+
: fillToolBackground(bodyText(theme.fg("warning", diagnostic), theme)),
|
|
369
369
|
);
|
|
370
370
|
return isPartial ? text : completed(true);
|
|
371
371
|
}
|
|
@@ -374,7 +374,7 @@ export function renderGatedCommandResult(
|
|
|
374
374
|
const rendered = typeof details._render === "string" ? details._render : "";
|
|
375
375
|
if (!rendered) {
|
|
376
376
|
const { summary } = renderBashOutput(rendered, code, theme);
|
|
377
|
-
text.setText(fillToolBackground(
|
|
377
|
+
text.setText(fillToolBackground(bodyLine(summary, theme)));
|
|
378
378
|
return isPartial ? text : completed(details.outcome !== "success");
|
|
379
379
|
}
|
|
380
380
|
|
package/src/tool-card.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { Box, Markdown } from "@earendil-works/pi-tui";
|
|
11
11
|
import { type CollapseState, tickCollapse } from "@xynogen/pix-runtime/collapse";
|
|
12
12
|
import { resolveBaseBackground } from "./ansi.ts";
|
|
13
|
-
import {
|
|
13
|
+
import { bodyLine, bodyText, frameToolResult, moreLines, reuseText } from "./frame.ts";
|
|
14
14
|
import {
|
|
15
15
|
type CollapsedToolStatus,
|
|
16
16
|
hideCollapsedToolCall,
|
|
@@ -195,7 +195,10 @@ export function bodyCardRenderer<D = Record<string, unknown>, S extends RenderSt
|
|
|
195
195
|
|
|
196
196
|
if (ctx.isError || !body.trim()) {
|
|
197
197
|
text.setText(
|
|
198
|
-
|
|
198
|
+
bodyText(
|
|
199
|
+
ctx.isError ? theme.fg("error", body || "Error") : theme.fg("muted", "(empty)"),
|
|
200
|
+
theme,
|
|
201
|
+
),
|
|
199
202
|
);
|
|
200
203
|
return isPartial ? text : frameToolResult(text, theme, ctx.isError);
|
|
201
204
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isAbsolute, relative, resolve } from "node:path";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import { getCapabilities, hyperlink, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
4
|
-
import { ANSI_CAPTURE_RE, BG_BASE, FG_LNUM, RST } from "./ansi.ts";
|
|
4
|
+
import { ANSI_CAPTURE_RE, BG_BASE, FG_LNUM, FG_RULE, RST } from "./ansi.ts";
|
|
5
5
|
import { MAX_PREVIEW_LINES } from "./config.ts";
|
|
6
6
|
import type { TextComponentCtor, TextComponentLike } from "./types.ts";
|
|
7
7
|
|
|
@@ -290,3 +290,14 @@ export function lineNumber(n: number, w: number): string {
|
|
|
290
290
|
const v = String(n);
|
|
291
291
|
return `${FG_LNUM}${" ".repeat(Math.max(0, w - v.length))}${v}${RST}`;
|
|
292
292
|
}
|
|
293
|
+
|
|
294
|
+
/** Columns taken by a numbered gutter: the number, a space, the rule, a space. */
|
|
295
|
+
export function gutterWidth(numberWidth: number): number {
|
|
296
|
+
return numberWidth + 3;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** One gutter cell in front of a code row; pass "" to blank a continuation row. */
|
|
300
|
+
export function lineGutter(n: number | "", numberWidth: number): string {
|
|
301
|
+
const cell = n === "" ? `${FG_LNUM}${" ".repeat(numberWidth)}${RST}` : lineNumber(n, numberWidth);
|
|
302
|
+
return `${cell} ${FG_RULE}│${RST} `;
|
|
303
|
+
}
|