@xynogen/pix-pretty 1.22.0 → 1.26.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 +4 -3
- package/src/gate-overlay.ts +4 -1
- package/src/icon-persist.ts +2 -7
- package/src/renderers.ts +27 -3
- package/src/transient-error.ts +68 -0
- package/src/types.ts +6 -1
- package/src/utils.ts +42 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-pretty",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.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",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"./context": "./src/tools/context.ts",
|
|
28
28
|
"./gate-overlay": "./src/gate-overlay.ts",
|
|
29
29
|
"./modal-frame": "./src/modal-frame.ts",
|
|
30
|
-
"./test-utils": "./src/test-utils.ts"
|
|
30
|
+
"./test-utils": "./src/test-utils.ts",
|
|
31
|
+
"./transient-error": "./src/transient-error.ts"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|
|
33
34
|
"test": "bun test"
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
"access": "public"
|
|
63
64
|
},
|
|
64
65
|
"dependencies": {
|
|
65
|
-
"@xynogen/pix-runtime": "^0.
|
|
66
|
+
"@xynogen/pix-runtime": "^0.10.0",
|
|
66
67
|
"chalk": "^4.1.2",
|
|
67
68
|
"cli-highlight": "^2.1.11",
|
|
68
69
|
"@ff-labs/fff-node": "^0.10.6",
|
package/src/gate-overlay.ts
CHANGED
|
@@ -218,7 +218,10 @@ function buildSections(opts: {
|
|
|
218
218
|
} else {
|
|
219
219
|
const label = config.mode === "sudo" ? (config.passwordLabel ?? "Sudo password:") : "Password:";
|
|
220
220
|
footer.push(theme.fg("dim", label));
|
|
221
|
-
if (passwordStatus)
|
|
221
|
+
if (passwordStatus)
|
|
222
|
+
footer.push(
|
|
223
|
+
theme.fg(passwordStatus === "Checking password…" ? "dim" : "error", passwordStatus),
|
|
224
|
+
);
|
|
222
225
|
footer.push(...maskedInput.render(inner));
|
|
223
226
|
footer.push("");
|
|
224
227
|
footer.push(theme.fg("muted", "←→/PgUp/PgDn inspect • enter confirm • esc cancel"));
|
package/src/icon-persist.ts
CHANGED
|
@@ -29,13 +29,8 @@ export function loadIconMode(): IconMode | undefined {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** Persist the icon mode to pix.json (`pretty.icons`). */
|
|
32
|
-
export function saveIconMode(mode: IconMode): Promise<void> {
|
|
33
|
-
|
|
34
|
-
() => undefined,
|
|
35
|
-
(err) => {
|
|
36
|
-
console.error("pix-pretty: persist icon mode failed:", err);
|
|
37
|
-
},
|
|
38
|
-
);
|
|
32
|
+
export async function saveIconMode(mode: IconMode): Promise<void> {
|
|
33
|
+
await updateConfig(prettySection, { icons: mode });
|
|
39
34
|
}
|
|
40
35
|
|
|
41
36
|
/**
|
package/src/renderers.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
1
|
+
import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
2
2
|
import { config } from "@xynogen/pix-runtime/config";
|
|
3
3
|
import { prettySection } from "@xynogen/pix-runtime/sections";
|
|
4
4
|
|
|
5
|
-
import { FG_DIM, FG_RULE, RST } from "./ansi.js";
|
|
5
|
+
import { FG_DIM, FG_LNUM, FG_RULE, RST } from "./ansi.js";
|
|
6
6
|
import { MAX_PREVIEW_LINES } from "./config.js";
|
|
7
7
|
import { hlBlock } from "./highlight.js";
|
|
8
8
|
import { dirIcon, fileColor, fileIcon } from "./icons.js";
|
|
@@ -10,6 +10,18 @@ import { lang } from "./lang.js";
|
|
|
10
10
|
import type { FgTheme } from "./types.js";
|
|
11
11
|
import { lnum, normalizeLineEndings, pluralize, rule, termW } from "./utils.js";
|
|
12
12
|
|
|
13
|
+
/** Layout controls for {@link renderFileContent}. */
|
|
14
|
+
export interface RenderFileContentOptions {
|
|
15
|
+
/** Total render width. Defaults to the live terminal width (`termW()`). */
|
|
16
|
+
width?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Wrap over-wide code lines onto continuation rows instead of clipping the
|
|
19
|
+
* tail with `›`. Off by default (compact preview stays one row per line);
|
|
20
|
+
* expanded views pass `true` so no source text is hidden.
|
|
21
|
+
*/
|
|
22
|
+
wrapLongLines?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
13
25
|
/** Render syntax-highlighted file content with line numbers. */
|
|
14
26
|
export async function renderFileContent(
|
|
15
27
|
content: string,
|
|
@@ -17,6 +29,7 @@ export async function renderFileContent(
|
|
|
17
29
|
offset = 1,
|
|
18
30
|
maxLines = MAX_PREVIEW_LINES,
|
|
19
31
|
theme?: FgTheme,
|
|
32
|
+
options: RenderFileContentOptions = {},
|
|
20
33
|
): Promise<string> {
|
|
21
34
|
const normalizedContent = normalizeLineEndings(content);
|
|
22
35
|
const lines = normalizedContent.split("\n");
|
|
@@ -25,7 +38,7 @@ export async function renderFileContent(
|
|
|
25
38
|
const lg = lang(filePath);
|
|
26
39
|
const hl = await hlBlock(show.join("\n"), lg, theme);
|
|
27
40
|
|
|
28
|
-
const tw = termW();
|
|
41
|
+
const tw = options.width ?? termW();
|
|
29
42
|
const startLine = offset;
|
|
30
43
|
const endLine = startLine + show.length - 1;
|
|
31
44
|
const nw = Math.max(3, String(endLine).length);
|
|
@@ -38,6 +51,17 @@ export async function renderFileContent(
|
|
|
38
51
|
for (let i = 0; i < hl.length; i++) {
|
|
39
52
|
const ln = startLine + i;
|
|
40
53
|
const code = hl[i] ?? show[i] ?? "";
|
|
54
|
+
if (options.wrapLongLines && visibleWidth(code) > cw) {
|
|
55
|
+
// Expanded view: no tail is hidden. First row carries the line number,
|
|
56
|
+
// continuation rows indent under the gutter so the code column aligns.
|
|
57
|
+
const rows = wrapTextWithAnsi(code, cw);
|
|
58
|
+
const pad = " ".repeat(nw);
|
|
59
|
+
rows.forEach((rowText, r) => {
|
|
60
|
+
const gutter = r === 0 ? lnum(ln, nw) : `${FG_LNUM}${pad}${RST}`;
|
|
61
|
+
out.push(`${gutter} ${FG_RULE}│${RST} ${rowText}${RST}`);
|
|
62
|
+
});
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
41
65
|
const display = truncateToWidth(code, cw, `${FG_DIM}›`);
|
|
42
66
|
out.push(`${lnum(ln, nw)} ${FG_RULE}│${RST} ${display}${RST}`);
|
|
43
67
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Text, truncateToWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
import { rule } from "./utils.ts";
|
|
3
|
+
|
|
4
|
+
export const TRANSIENT_ERROR_TTL_MS = 30_000;
|
|
5
|
+
const WIDGET_KEY = "pix-transient-error";
|
|
6
|
+
const timers = new WeakMap<object, ReturnType<typeof setTimeout>>();
|
|
7
|
+
|
|
8
|
+
type TransientMessageTheme = {
|
|
9
|
+
fg(color: "error" | "warning" | "accent" | "muted" | "borderMuted", text: string): string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type TransientMessageLevel = "error" | "warning" | "info";
|
|
13
|
+
|
|
14
|
+
type WidgetFactory = (
|
|
15
|
+
tui: unknown,
|
|
16
|
+
theme: TransientMessageTheme,
|
|
17
|
+
) => { render(width: number): string[]; invalidate(): void };
|
|
18
|
+
|
|
19
|
+
export type TransientErrorUI = {
|
|
20
|
+
setWidget(
|
|
21
|
+
key: string,
|
|
22
|
+
content: WidgetFactory | undefined,
|
|
23
|
+
options?: { placement?: "aboveEditor" | "belowEditor" },
|
|
24
|
+
): void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Show newest runtime message above the editor (on top of the prompt bar), then remove it after 30 seconds. */
|
|
28
|
+
export function showTransientMessage(
|
|
29
|
+
ui: TransientErrorUI,
|
|
30
|
+
message: string,
|
|
31
|
+
level: TransientMessageLevel = "error",
|
|
32
|
+
): void {
|
|
33
|
+
const previous = timers.get(ui);
|
|
34
|
+
if (previous) clearTimeout(previous);
|
|
35
|
+
|
|
36
|
+
ui.setWidget(
|
|
37
|
+
WIDGET_KEY,
|
|
38
|
+
(_tui, theme) => {
|
|
39
|
+
const text = new Text("", 0, 0);
|
|
40
|
+
return {
|
|
41
|
+
render(width: number) {
|
|
42
|
+
const color = level === "info" ? "accent" : level;
|
|
43
|
+
const prefix = theme.fg(color, `${level} `);
|
|
44
|
+
text.setText(prefix + theme.fg("muted", message.replace(/\s+/g, " ").trim()));
|
|
45
|
+
return [
|
|
46
|
+
rule(width, (glyphs) => theme.fg("borderMuted", glyphs)),
|
|
47
|
+
truncateToWidth(text.render(width)[0] ?? "", width),
|
|
48
|
+
];
|
|
49
|
+
},
|
|
50
|
+
invalidate: () => text.invalidate(),
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
{ placement: "aboveEditor" },
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const timer = setTimeout(() => {
|
|
57
|
+
if (timers.get(ui) !== timer) return;
|
|
58
|
+
timers.delete(ui);
|
|
59
|
+
ui.setWidget(WIDGET_KEY, undefined);
|
|
60
|
+
}, TRANSIENT_ERROR_TTL_MS);
|
|
61
|
+
timer.unref?.();
|
|
62
|
+
timers.set(ui, timer);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Error-level convenience wrapper. */
|
|
66
|
+
export function showTransientError(ui: TransientErrorUI, message: string): void {
|
|
67
|
+
showTransientMessage(ui, message, "error");
|
|
68
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -24,7 +24,12 @@ export type BundledTheme = string;
|
|
|
24
24
|
// Config
|
|
25
25
|
// ---------------------------------------------------------------------------
|
|
26
26
|
|
|
27
|
-
export type BgTheme = {
|
|
27
|
+
export type BgTheme = {
|
|
28
|
+
getBgAnsi?: (key: string) => string;
|
|
29
|
+
// Semantic background wrapper exposed by Pi's theme (e.g. modal fills). Optional
|
|
30
|
+
// so mock/partial themes remain assignable; real runtime themes provide it.
|
|
31
|
+
bg?: (key: string, text: string) => string;
|
|
32
|
+
};
|
|
28
33
|
|
|
29
34
|
export type FgTheme = {
|
|
30
35
|
fg: (key: string, text: string) => string;
|
package/src/utils.ts
CHANGED
|
@@ -87,7 +87,7 @@ const RESULT_FRAME = Symbol("pix.resultFrame");
|
|
|
87
87
|
type FramedResultComponent = ResultComponent & {
|
|
88
88
|
[RESULT_FRAME]: {
|
|
89
89
|
component: FramableComponent;
|
|
90
|
-
update(theme: ResultFrameTheme, isError: boolean): void;
|
|
90
|
+
update(theme: ResultFrameTheme, isError: boolean, section: boolean): void;
|
|
91
91
|
};
|
|
92
92
|
};
|
|
93
93
|
|
|
@@ -519,9 +519,11 @@ export function shortPath(cwd: string, home: string, p: string): string {
|
|
|
519
519
|
/** Paints a rule line. Callers pass `(s) => theme.fg(status, s)` so the frame
|
|
520
520
|
* tint follows the active theme (success/error/warning). Default = neutral FG_RULE. */
|
|
521
521
|
export type RulePaint = (glyphs: string) => string;
|
|
522
|
+
export type RuleStyle = "solid" | "dashed";
|
|
522
523
|
|
|
523
|
-
|
|
524
|
-
|
|
524
|
+
/** Render a full-width solid rule or a spaced ASCII dashed separator. */
|
|
525
|
+
export function rule(w: number, paint?: RulePaint, style: RuleStyle = "solid"): string {
|
|
526
|
+
const glyphs = style === "dashed" ? "- ".repeat(Math.ceil(w / 2)).slice(0, w) : "─".repeat(w);
|
|
525
527
|
return paint ? paint(glyphs) : `${FG_RULE}${glyphs}${RST}`;
|
|
526
528
|
}
|
|
527
529
|
|
|
@@ -549,7 +551,7 @@ export function sectionRule(line: string, theme: FgTheme, width: number): string
|
|
|
549
551
|
return theme.fg("muted", `${"─".repeat(lead)}${label}${"─".repeat(tail)}`);
|
|
550
552
|
}
|
|
551
553
|
|
|
552
|
-
/** Decorate
|
|
554
|
+
/** Decorate completed tool output with status-colored default chrome. */
|
|
553
555
|
export function frameToolResult<T extends FramableComponent & { setText(value: string): void }>(
|
|
554
556
|
component: T,
|
|
555
557
|
theme: ResultFrameTheme,
|
|
@@ -565,25 +567,46 @@ export function frameToolResult(
|
|
|
565
567
|
theme: ResultFrameTheme,
|
|
566
568
|
isError: boolean,
|
|
567
569
|
): ResultComponent {
|
|
570
|
+
return decorateToolResult(component, theme, isError, false);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/** Decorate explicit expanded/detail sections with solid top and bottom rules. */
|
|
574
|
+
export function frameToolSection(
|
|
575
|
+
component: FramableComponent,
|
|
576
|
+
theme: ResultFrameTheme,
|
|
577
|
+
isError: boolean,
|
|
578
|
+
): ResultComponent {
|
|
579
|
+
return decorateToolResult(component, theme, isError, true);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function decorateToolResult(
|
|
583
|
+
component: FramableComponent,
|
|
584
|
+
theme: ResultFrameTheme,
|
|
585
|
+
isError: boolean,
|
|
586
|
+
section: boolean,
|
|
587
|
+
): ResultComponent & Partial<TextComponentLike> {
|
|
568
588
|
const existing = component as Partial<FramedResultComponent>;
|
|
569
589
|
if (existing[RESULT_FRAME]) {
|
|
570
|
-
existing[RESULT_FRAME].update(theme, isError);
|
|
590
|
+
existing[RESULT_FRAME].update(theme, isError, section);
|
|
571
591
|
return component as ResultComponent;
|
|
572
592
|
}
|
|
573
593
|
let frameTheme = theme;
|
|
574
594
|
let failed = isError;
|
|
595
|
+
let solid = section;
|
|
575
596
|
const framed: FramedResultComponent & Partial<TextComponentLike> = {
|
|
576
597
|
[RESULT_FRAME]: {
|
|
577
598
|
component,
|
|
578
|
-
update(nextTheme, nextError) {
|
|
599
|
+
update(nextTheme, nextError, nextSection) {
|
|
579
600
|
frameTheme = nextTheme;
|
|
580
601
|
failed = nextError;
|
|
602
|
+
solid = nextSection;
|
|
581
603
|
},
|
|
582
604
|
},
|
|
583
605
|
wantsKeyRelease: component.wantsKeyRelease,
|
|
584
606
|
render(width) {
|
|
585
607
|
const paint = (line: string) => frameTheme.fg(failed ? "error" : "success", line);
|
|
586
|
-
|
|
608
|
+
const lines = component.render?.(width) ?? [];
|
|
609
|
+
return solid ? sectionFrame(lines, [], width, paint) : ruleFrame(lines, [], width, paint);
|
|
587
610
|
},
|
|
588
611
|
invalidate() {
|
|
589
612
|
component.invalidate?.();
|
|
@@ -602,16 +625,24 @@ export function unframeToolResult<T extends FramableComponent>(component: T): T
|
|
|
602
625
|
}
|
|
603
626
|
|
|
604
627
|
/**
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
* single source of the "rule top, rule bottom" invariant so every tool's result
|
|
608
|
-
* block is framed identically — MCP and the shell tools share this.
|
|
628
|
+
* Default completed-tool chrome: unchanged body, full-width dashed close, then
|
|
629
|
+
* footer lines. Existing callers inherit this distro-wide presentation.
|
|
609
630
|
*/
|
|
610
631
|
export function ruleFrame(
|
|
611
632
|
bodyLines: string[],
|
|
612
633
|
footerLines: string[] = [],
|
|
613
634
|
width?: number,
|
|
614
635
|
paint?: RulePaint,
|
|
636
|
+
): string[] {
|
|
637
|
+
return [...bodyLines, rule(width ?? termW(), paint, "dashed"), ...footerLines];
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** Explicit solid top/bottom frame for sections that need stronger separation. */
|
|
641
|
+
export function sectionFrame(
|
|
642
|
+
bodyLines: string[],
|
|
643
|
+
footerLines: string[] = [],
|
|
644
|
+
width?: number,
|
|
645
|
+
paint?: RulePaint,
|
|
615
646
|
): string[] {
|
|
616
647
|
const r = rule(width ?? termW(), paint);
|
|
617
648
|
return [r, ...bodyLines, r, ...footerLines];
|