@xynogen/pix-pretty 3.5.0 → 3.5.1
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 +16 -7
- package/src/frame.ts +12 -0
- package/src/renderers.ts +7 -6
- package/src/shell-tool.ts +1 -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 { bodyLine } from "./frame.ts";
|
|
15
|
+
import { BODY_PAD, 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";
|
|
@@ -189,7 +189,13 @@ function diffWidth(): number {
|
|
|
189
189
|
// Single source of truth: utils.terminalWidth caches, falls back to tty ioctl, and
|
|
190
190
|
// invalidates on resize. Diff layout needs a hard floor of 80 cols for the
|
|
191
191
|
// split-view column math (no ceiling — fill the true width on ultrawide).
|
|
192
|
-
|
|
192
|
+
// The diff sits in the tool-result body column, so the indent comes out of that width.
|
|
193
|
+
return Math.max(80, terminalWidth()) - BODY_PAD.length;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Rows indented into the body column, like every other tool-result body. */
|
|
197
|
+
function inBodyColumn(rows: readonly string[]): string[] {
|
|
198
|
+
return rows.map((row) => BODY_PAD + row);
|
|
193
199
|
}
|
|
194
200
|
|
|
195
201
|
/** Pad/truncate `s` to exactly `w` visible chars. ANSI-aware. */
|
|
@@ -489,7 +495,8 @@ function at<T>(arr: T[], i: number): T {
|
|
|
489
495
|
|
|
490
496
|
function shouldUseSplit(diff: ParsedDiff, tw: number, maxRows = MAX_PREVIEW_LINES): boolean {
|
|
491
497
|
if (!diff.lines.length) return false;
|
|
492
|
-
|
|
498
|
+
// The configured threshold is a terminal width; `tw` is the body column inside it.
|
|
499
|
+
if (tw + BODY_PAD.length < SPLIT_MIN_WIDTH) return false;
|
|
493
500
|
|
|
494
501
|
const nw = Math.max(
|
|
495
502
|
2,
|
|
@@ -668,12 +675,13 @@ export async function renderUnified(
|
|
|
668
675
|
}
|
|
669
676
|
|
|
670
677
|
out.push(rule(tw));
|
|
678
|
+
const rows = inBodyColumn(out);
|
|
671
679
|
if (diff.lines.length > vis.length) {
|
|
672
|
-
|
|
680
|
+
rows.push(
|
|
673
681
|
`${BG_BASE}${bodyLine(`${FG_DIM}… ${diff.lines.length - vis.length} more lines${RST}`)}`,
|
|
674
682
|
);
|
|
675
683
|
}
|
|
676
|
-
return
|
|
684
|
+
return rows.join("\n");
|
|
677
685
|
}
|
|
678
686
|
|
|
679
687
|
// ---------------------------------------------------------------------------
|
|
@@ -852,8 +860,9 @@ export async function renderSplit(
|
|
|
852
860
|
}
|
|
853
861
|
|
|
854
862
|
out.push(`${rule(half)}${FG_RULE}┊${RST}${rule(half)}`);
|
|
863
|
+
const framed = inBodyColumn(out);
|
|
855
864
|
if (rows.length > vis.length) {
|
|
856
|
-
|
|
865
|
+
framed.push(`${BG_BASE}${bodyLine(`${FG_DIM}… ${rows.length - vis.length} more lines${RST}`)}`);
|
|
857
866
|
}
|
|
858
|
-
return
|
|
867
|
+
return framed.join("\n");
|
|
859
868
|
}
|
package/src/frame.ts
CHANGED
|
@@ -217,6 +217,18 @@ export function bodyRows(
|
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
/**
|
|
221
|
+
* A call title that may wrap: `renderTitle` output plus its arguments. Rows after the first
|
|
222
|
+
* hang in the body column under the tool name, not at column 0.
|
|
223
|
+
*/
|
|
224
|
+
export function titleBlock(title: string, rest = ""): BodyComponent {
|
|
225
|
+
const text = rest ? `${title} ${rest}` : title;
|
|
226
|
+
return {
|
|
227
|
+
render: (width) => wrapUnderIndent(text, width, BODY_PAD.length),
|
|
228
|
+
invalidate() {},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
220
232
|
/** Content that already sits in the body column, so `bodyRows` keeps it as is. */
|
|
221
233
|
export type Body = { readonly text: string };
|
|
222
234
|
|
package/src/renderers.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { prettySection } from "@xynogen/pix-runtime/sections";
|
|
|
4
4
|
|
|
5
5
|
import { FG_DIM, FG_RULE, RST } from "./ansi.ts";
|
|
6
6
|
import { MAX_PREVIEW_LINES } from "./config.ts";
|
|
7
|
-
import { bodyLine, bodyWidth, type ExpandHintCtx, expandHint, rule } from "./frame.ts";
|
|
7
|
+
import { BODY_PAD, 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";
|
|
@@ -45,7 +45,8 @@ export async function renderFileContent(
|
|
|
45
45
|
const codeRows = show.map((line, i) => hl[i] ?? line);
|
|
46
46
|
const body = theme && total > maxLines ? fadeTail(codeRows, theme) : codeRows;
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
// The frame sits in the tool-result body column, under the title, not at column 0.
|
|
49
|
+
const tw = Math.max(1, (options.width ?? terminalWidth()) - BODY_PAD.length);
|
|
49
50
|
const startLine = offset;
|
|
50
51
|
const endLine = startLine + show.length - 1;
|
|
51
52
|
const nw = Math.max(3, String(endLine).length);
|
|
@@ -53,7 +54,7 @@ export async function renderFileContent(
|
|
|
53
54
|
const cw = Math.max(1, tw - gw);
|
|
54
55
|
|
|
55
56
|
const out: string[] = [];
|
|
56
|
-
out.push(rule(tw));
|
|
57
|
+
out.push(BODY_PAD + rule(tw));
|
|
57
58
|
|
|
58
59
|
for (let i = 0; i < body.length; i++) {
|
|
59
60
|
const ln = startLine + i;
|
|
@@ -63,15 +64,15 @@ export async function renderFileContent(
|
|
|
63
64
|
// continuation rows indent under the gutter so the code column aligns.
|
|
64
65
|
const rows = wrapTextWithAnsi(code, cw);
|
|
65
66
|
rows.forEach((rowText, r) => {
|
|
66
|
-
out.push(`${lineGutter(r === 0 ? ln : "", nw)}${rowText}${RST}`);
|
|
67
|
+
out.push(`${BODY_PAD}${lineGutter(r === 0 ? ln : "", nw)}${rowText}${RST}`);
|
|
67
68
|
});
|
|
68
69
|
continue;
|
|
69
70
|
}
|
|
70
71
|
const display = truncateToWidth(code, cw, `${FG_DIM}›`);
|
|
71
|
-
out.push(`${lineGutter(ln, nw)}${display}${RST}`);
|
|
72
|
+
out.push(`${BODY_PAD}${lineGutter(ln, nw)}${display}${RST}`);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
out.push(rule(tw));
|
|
75
|
+
out.push(BODY_PAD + rule(tw));
|
|
75
76
|
if (total > maxLines) {
|
|
76
77
|
const more = `… ${pluralize(total - maxLines, "more line")} (${total} total) `;
|
|
77
78
|
out.push(
|
package/src/shell-tool.ts
CHANGED
|
@@ -280,7 +280,7 @@ export function gatedCancellation(action: string): {
|
|
|
280
280
|
return {
|
|
281
281
|
outcome: "timed-out",
|
|
282
282
|
cancellationKind: "timeout",
|
|
283
|
-
text: "Cancelled — Timed out — auto-denied.",
|
|
283
|
+
text: "Cancelled — Timed out — auto-denied. Often the user is away (AFK): rerun this call when they return.",
|
|
284
284
|
};
|
|
285
285
|
if (action === "denied")
|
|
286
286
|
return { outcome: "denied", cancellationKind: "denied", text: "Cancelled — Denied by user." };
|