@xynogen/pix-pretty 3.0.0 → 3.0.2
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 +2 -2
- package/src/command-preview.ts +7 -5
- package/src/confirm.ts +8 -7
- package/src/frame.ts +5 -5
- package/src/gate-overlay.ts +14 -13
- package/src/index.ts +0 -2
- package/src/modal-frame.ts +5 -1
- package/src/progress.ts +1 -1
- package/src/provider-picker.ts +7 -3
- package/src/text.ts +14 -3
- package/src/transient-error.ts +1 -1
- package/src/tui.ts +4 -0
- package/src/utils.ts +3 -3
- package/src/overlay-images.ts +0 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-pretty",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@xynogen/pix-runtime": "^0.22.
|
|
79
|
+
"@xynogen/pix-runtime": "^0.22.2",
|
|
80
80
|
"chalk": "^4.1.2",
|
|
81
81
|
"cli-highlight": "^2.1.11",
|
|
82
82
|
"@ff-labs/fff-node": "^0.10.6",
|
package/src/command-preview.ts
CHANGED
|
@@ -43,9 +43,9 @@ export function commandPreview(
|
|
|
43
43
|
let replacement: string | undefined;
|
|
44
44
|
const text = new Text("", 0, 0);
|
|
45
45
|
let memo:
|
|
46
|
-
| { width: number; styled: string; replacement: string | undefined; lines: string[] }
|
|
46
|
+
| { width: number; styled: string; replacement: string | undefined; lines: readonly string[] }
|
|
47
47
|
| undefined;
|
|
48
|
-
const layout = (width: number): string[] => {
|
|
48
|
+
const layout = (width: number): readonly string[] => {
|
|
49
49
|
if (replacement !== undefined) {
|
|
50
50
|
text.setText(replacement);
|
|
51
51
|
return replacement ? text.render(width) : [];
|
|
@@ -78,7 +78,7 @@ export function commandPreview(
|
|
|
78
78
|
memo = undefined;
|
|
79
79
|
text.invalidate();
|
|
80
80
|
},
|
|
81
|
-
render(width: number): string[] {
|
|
81
|
+
render(width: number): readonly string[] {
|
|
82
82
|
if (
|
|
83
83
|
memo?.width === width &&
|
|
84
84
|
memo.styled === current.styled &&
|
|
@@ -102,7 +102,9 @@ export function collapsedCommandRow(
|
|
|
102
102
|
let text = `${prefix}${theme.fg("dim", plain)}`;
|
|
103
103
|
let replaced = false;
|
|
104
104
|
const replacementText = new Text("", 0, 0);
|
|
105
|
-
let memo:
|
|
105
|
+
let memo:
|
|
106
|
+
| { width: number; text: string; replaced: boolean; lines: readonly string[] }
|
|
107
|
+
| undefined;
|
|
106
108
|
return {
|
|
107
109
|
setText(value: string) {
|
|
108
110
|
text = value;
|
|
@@ -113,7 +115,7 @@ export function collapsedCommandRow(
|
|
|
113
115
|
memo = undefined;
|
|
114
116
|
replacementText.invalidate();
|
|
115
117
|
},
|
|
116
|
-
render(width: number): string[] {
|
|
118
|
+
render(width: number): readonly string[] {
|
|
117
119
|
if (memo?.width === width && memo.text === text && memo.replaced === replaced)
|
|
118
120
|
return memo.lines;
|
|
119
121
|
if (replaced) {
|
package/src/confirm.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
terminalModalHeight,
|
|
16
16
|
} from "./modal-frame.ts";
|
|
17
17
|
import { createOverlayLifecycle } from "./overlay-lifecycle.ts";
|
|
18
|
+
import { alignDashLabels } from "./text.ts";
|
|
18
19
|
import { type UserPromptOptions, type UserPromptState, withUserPrompt } from "./user-prompt.ts";
|
|
19
20
|
|
|
20
21
|
// Minimal structural type for the `ctx.ui.custom` host call.
|
|
@@ -25,7 +26,7 @@ interface CustomTheme {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
interface CustomComponent {
|
|
28
|
-
render(width: number): string[];
|
|
29
|
+
render(width: number): readonly string[];
|
|
29
30
|
invalidate(): void;
|
|
30
31
|
handleInput(data: string): void;
|
|
31
32
|
focused?: boolean;
|
|
@@ -52,9 +53,9 @@ export interface ConfirmOptions {
|
|
|
52
53
|
title: string;
|
|
53
54
|
/** Optional body lines rendered under the title. */
|
|
54
55
|
body?: string[];
|
|
55
|
-
/** Label for the confirm choice. Default "
|
|
56
|
+
/** Label for the confirm choice. Default "Allow — proceed". */
|
|
56
57
|
confirmLabel?: string;
|
|
57
|
-
/** Label for the deny choice. Default "
|
|
58
|
+
/** Label for the deny choice. Default "Deny — cancel". */
|
|
58
59
|
denyLabel?: string;
|
|
59
60
|
/** Accent colour for border + selection. Default "accent". */
|
|
60
61
|
accent?: string;
|
|
@@ -88,18 +89,18 @@ export async function confirmOverlay(ui: ConfirmUI, opts: ConfirmOptions): Promi
|
|
|
88
89
|
lifecycle.onCleanup(() => clearInterval(ticker));
|
|
89
90
|
lifecycle.bind(done);
|
|
90
91
|
|
|
91
|
-
const choices: SelectItem[] = [
|
|
92
|
+
const choices: SelectItem[] = alignDashLabels([
|
|
92
93
|
{
|
|
93
94
|
value: "yes",
|
|
94
|
-
label: opts.confirmLabel ?? "
|
|
95
|
+
label: opts.confirmLabel ?? "Allow — proceed",
|
|
95
96
|
description: "Proceed",
|
|
96
97
|
},
|
|
97
98
|
{
|
|
98
99
|
value: "no",
|
|
99
|
-
label: opts.denyLabel ?? "
|
|
100
|
+
label: opts.denyLabel ?? "Deny — cancel",
|
|
100
101
|
description: "Cancel",
|
|
101
102
|
},
|
|
102
|
-
];
|
|
103
|
+
]);
|
|
103
104
|
|
|
104
105
|
const selectList = new SelectList(
|
|
105
106
|
choices,
|
package/src/frame.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { TextComponentCtor, TextComponentLike } from "./types.ts";
|
|
|
6
6
|
import { terminalWidth } from "./utils.ts";
|
|
7
7
|
|
|
8
8
|
type ResultComponent = {
|
|
9
|
-
render(width: number): string[];
|
|
9
|
+
render(width: number): readonly string[];
|
|
10
10
|
invalidate(): void;
|
|
11
11
|
handleInput?(data: string): void;
|
|
12
12
|
wantsKeyRelease?: boolean;
|
|
@@ -230,8 +230,8 @@ export function reuseText(
|
|
|
230
230
|
* footer lines. Existing callers inherit this distro-wide presentation.
|
|
231
231
|
*/
|
|
232
232
|
export function ruleFrame(
|
|
233
|
-
bodyLines: string[],
|
|
234
|
-
footerLines: string[] = [],
|
|
233
|
+
bodyLines: readonly string[],
|
|
234
|
+
footerLines: readonly string[] = [],
|
|
235
235
|
width?: number,
|
|
236
236
|
paint?: RulePaint,
|
|
237
237
|
): string[] {
|
|
@@ -265,8 +265,8 @@ export function outputBodyRows(
|
|
|
265
265
|
|
|
266
266
|
/** Explicit solid top/bottom frame for sections that need stronger separation. */
|
|
267
267
|
export function sectionFrame(
|
|
268
|
-
bodyLines: string[],
|
|
269
|
-
footerLines: string[] = [],
|
|
268
|
+
bodyLines: readonly string[],
|
|
269
|
+
footerLines: readonly string[] = [],
|
|
270
270
|
width?: number,
|
|
271
271
|
paint?: RulePaint,
|
|
272
272
|
): string[] {
|
package/src/gate-overlay.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
terminalModalHeight,
|
|
29
29
|
} from "./modal-frame.ts";
|
|
30
30
|
import { createOverlayLifecycle } from "./overlay-lifecycle.ts";
|
|
31
|
+
import { alignDashLabels } from "./text.ts";
|
|
31
32
|
import { type UserPromptOptions, type UserPromptState, withUserPrompt } from "./user-prompt.ts";
|
|
32
33
|
|
|
33
34
|
// ── Types ─────────────────────────────────────────────────────────────────────
|
|
@@ -75,7 +76,7 @@ interface BaseConfig {
|
|
|
75
76
|
/**
|
|
76
77
|
* Choices shown in the SelectList.
|
|
77
78
|
* A choice whose value is in approveValue counts as approval.
|
|
78
|
-
* Default: [{ value:"yes", label:"Allow" }, { value:"no", label:"Deny" }]
|
|
79
|
+
* Default: [{ value:"yes", label:"Allow — proceed" }, { value:"no", label:"Deny — cancel" }]
|
|
79
80
|
*/
|
|
80
81
|
choices?: OverlayChoice[];
|
|
81
82
|
/** Choice value(s) that mean "approved". Default "yes". `OverlayResult.choice` tells them apart. */
|
|
@@ -111,7 +112,7 @@ interface OverlayTui {
|
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
interface OverlayComponent {
|
|
114
|
-
render(width: number): string[];
|
|
115
|
+
render(width: number): readonly string[];
|
|
115
116
|
invalidate(): void;
|
|
116
117
|
handleInput(data: string): void;
|
|
117
118
|
focused?: boolean;
|
|
@@ -132,8 +133,8 @@ export interface OverlayUI {
|
|
|
132
133
|
// ── Constants ─────────────────────────────────────────────────────────────────
|
|
133
134
|
|
|
134
135
|
const DEFAULT_CHOICES: OverlayChoice[] = [
|
|
135
|
-
{ value: "yes", label: "Allow", description: "Proceed" },
|
|
136
|
-
{ value: "no", label: "Deny", description: "
|
|
136
|
+
{ value: "yes", label: "Allow — proceed", description: "Proceed" },
|
|
137
|
+
{ value: "no", label: "Deny — cancel", description: "Cancel" },
|
|
137
138
|
];
|
|
138
139
|
|
|
139
140
|
function asPageKeybindings(value: unknown): ModalPageKeybindings | undefined {
|
|
@@ -251,8 +252,8 @@ function buildSections(opts: {
|
|
|
251
252
|
* accent: "warning",
|
|
252
253
|
* timeoutMs: 30_000,
|
|
253
254
|
* choices: [
|
|
254
|
-
* { value: "yes", label: "Allow", description: "Run the command" },
|
|
255
|
-
* { value: "no", label: "Deny",
|
|
255
|
+
* { value: "yes", label: "Allow — run command", description: "Run the command" },
|
|
256
|
+
* { value: "no", label: "Deny — block command", description: "Block the command" },
|
|
256
257
|
* ],
|
|
257
258
|
* });
|
|
258
259
|
* ```
|
|
@@ -306,11 +307,9 @@ export async function showOverlay(ui: OverlayUI, config: OverlayConfig): Promise
|
|
|
306
307
|
};
|
|
307
308
|
|
|
308
309
|
// ── components ──────────────────────────────────────────────────
|
|
309
|
-
const selectItems: SelectItem[] =
|
|
310
|
-
value: c.value,
|
|
311
|
-
|
|
312
|
-
description: c.description,
|
|
313
|
-
}));
|
|
310
|
+
const selectItems: SelectItem[] = alignDashLabels(
|
|
311
|
+
choices.map((c) => ({ value: c.value, label: c.label, description: c.description })),
|
|
312
|
+
);
|
|
314
313
|
|
|
315
314
|
const selectList = new SelectList(
|
|
316
315
|
selectItems,
|
|
@@ -346,7 +345,9 @@ export async function showOverlay(ui: OverlayUI, config: OverlayConfig): Promise
|
|
|
346
345
|
}
|
|
347
346
|
|
|
348
347
|
// ── event wiring ─────────────────────────────────────────────────
|
|
348
|
+
let picked: string | undefined;
|
|
349
349
|
selectList.onSelect = (item) => {
|
|
350
|
+
picked = item.value;
|
|
350
351
|
if (!approveVals.includes(item.value)) {
|
|
351
352
|
finish({ action: "denied", choice: item.value });
|
|
352
353
|
} else if (config.mode === "sudo") {
|
|
@@ -360,7 +361,7 @@ export async function showOverlay(ui: OverlayUI, config: OverlayConfig): Promise
|
|
|
360
361
|
|
|
361
362
|
maskedInput.onSubmit = async (pw) => {
|
|
362
363
|
if (config.mode !== "sudo" || !config.validatePassword) {
|
|
363
|
-
finish({ action: "approved", password: pw });
|
|
364
|
+
finish({ action: "approved", password: pw, choice: picked });
|
|
364
365
|
return;
|
|
365
366
|
}
|
|
366
367
|
if (!pw.trim() || validatingPassword) return;
|
|
@@ -378,7 +379,7 @@ export async function showOverlay(ui: OverlayUI, config: OverlayConfig): Promise
|
|
|
378
379
|
if (lifecycle.closed) return;
|
|
379
380
|
validatingPassword = false;
|
|
380
381
|
if (valid) {
|
|
381
|
-
finish({ action: "approved", password: pw });
|
|
382
|
+
finish({ action: "approved", password: pw, choice: picked });
|
|
382
383
|
return;
|
|
383
384
|
}
|
|
384
385
|
|
package/src/index.ts
CHANGED
|
@@ -15,10 +15,8 @@ import { fffState } from "./fff.ts";
|
|
|
15
15
|
import { clearHighlightCache } from "./highlight.ts";
|
|
16
16
|
import { initIconMode } from "./icon-persist.ts";
|
|
17
17
|
import { installOrderedWidgets } from "./ordered-widgets.ts";
|
|
18
|
-
import { installOverlayImages } from "./overlay-images.ts";
|
|
19
18
|
|
|
20
19
|
export default function piPrettyExtension(pi: ExtensionAPI): void {
|
|
21
|
-
installOverlayImages();
|
|
22
20
|
once(pi, "pix-pretty-widgets", () => {
|
|
23
21
|
let restore: (() => void) | undefined;
|
|
24
22
|
pi.on("session_start", (_event, ctx) => {
|
package/src/modal-frame.ts
CHANGED
|
@@ -174,7 +174,11 @@ export interface JoinColumnsOptions {
|
|
|
174
174
|
* padded with blanks. Pure: no wrapping, no color; callers style the cells and
|
|
175
175
|
* the optional `sep`.
|
|
176
176
|
*/
|
|
177
|
-
export function joinColumns(
|
|
177
|
+
export function joinColumns(
|
|
178
|
+
left: readonly string[],
|
|
179
|
+
right: readonly string[],
|
|
180
|
+
opts: JoinColumnsOptions,
|
|
181
|
+
): string[] {
|
|
178
182
|
const divider = opts.sep ?? " ".repeat(Math.max(0, opts.gap ?? 2));
|
|
179
183
|
const height = Math.max(left.length, right.length);
|
|
180
184
|
const rows: string[] = [];
|
package/src/progress.ts
CHANGED
package/src/provider-picker.ts
CHANGED
|
@@ -66,7 +66,7 @@ export interface ProviderPickerUI {
|
|
|
66
66
|
keybindings: KeybindingsManager,
|
|
67
67
|
done: (value: T) => void,
|
|
68
68
|
) => {
|
|
69
|
-
render(width: number): string[];
|
|
69
|
+
render(width: number): readonly string[];
|
|
70
70
|
invalidate(): void;
|
|
71
71
|
handleInput(data: string): void;
|
|
72
72
|
dispose?(): void;
|
|
@@ -90,7 +90,11 @@ function defaultExample(name: string): string {
|
|
|
90
90
|
export function renderProviderRows(
|
|
91
91
|
opts: ProviderPickerOptions,
|
|
92
92
|
theme: Pick<PickerTheme, "fg">,
|
|
93
|
-
state: {
|
|
93
|
+
state: {
|
|
94
|
+
cursor: number;
|
|
95
|
+
expanded: Set<string>;
|
|
96
|
+
field?: { render(width: number): readonly string[] };
|
|
97
|
+
},
|
|
94
98
|
width: number,
|
|
95
99
|
): { lines: string[]; nodes: Node[]; selected: { start: number; end: number } } {
|
|
96
100
|
const aliases = opts.envAliases ?? {};
|
|
@@ -196,7 +200,7 @@ export function renderSettingsRows(
|
|
|
196
200
|
rows: SettingsRow[],
|
|
197
201
|
theme: Pick<PickerTheme, "fg">,
|
|
198
202
|
selected: number,
|
|
199
|
-
field?: { render(width: number): string[] },
|
|
203
|
+
field?: { render(width: number): readonly string[] },
|
|
200
204
|
width = 80,
|
|
201
205
|
list?: { choices: SettingsChoice[]; cursor: number; query: string; max?: number },
|
|
202
206
|
): { lines: string[]; rowLines: number[]; listLine?: number } {
|
package/src/text.ts
CHANGED
|
@@ -132,12 +132,12 @@ export function fadeTextRow(
|
|
|
132
132
|
*
|
|
133
133
|
* Blank rows never take a fade step: the steps go to the last rows with text.
|
|
134
134
|
*/
|
|
135
|
-
export function fadeRowsOf(
|
|
136
|
-
lines:
|
|
135
|
+
export function fadeRowsOf<T extends readonly string[]>(
|
|
136
|
+
lines: T,
|
|
137
137
|
theme: FadeTheme,
|
|
138
138
|
maxLines: number,
|
|
139
139
|
fadeRows = 3,
|
|
140
|
-
): string[] {
|
|
140
|
+
): T | string[] {
|
|
141
141
|
if (lines.length <= maxLines) return lines;
|
|
142
142
|
const paint = fadePaint(theme);
|
|
143
143
|
// At most a third of the preview fades, so short previews stay readable.
|
|
@@ -178,3 +178,14 @@ export function trimToUndefined(value: string | undefined): string | undefined {
|
|
|
178
178
|
const trimmed = value?.trim();
|
|
179
179
|
return trimmed ? trimmed : undefined;
|
|
180
180
|
}
|
|
181
|
+
|
|
182
|
+
/** Pad each `Head — rest` label so the dashes line up in one column; labels without a dash stay as-is. */
|
|
183
|
+
export function alignDashLabels<T extends { label: string }>(items: T[]): T[] {
|
|
184
|
+
const heads = items.map((item) => item.label.indexOf(" — "));
|
|
185
|
+
const width = Math.max(-1, ...heads);
|
|
186
|
+
return items.map((item, i) => {
|
|
187
|
+
const at = heads[i] ?? -1;
|
|
188
|
+
if (at < 0) return item;
|
|
189
|
+
return { ...item, label: item.label.slice(0, at).padEnd(width) + item.label.slice(at) };
|
|
190
|
+
});
|
|
191
|
+
}
|
package/src/transient-error.ts
CHANGED
|
@@ -30,7 +30,7 @@ export type TransientMessageLevel = "error" | "warning" | "info";
|
|
|
30
30
|
type WidgetFactory = (
|
|
31
31
|
tui: unknown,
|
|
32
32
|
theme: TransientMessageTheme,
|
|
33
|
-
) => { render(width: number): string[]; invalidate(): void };
|
|
33
|
+
) => { render(width: number): readonly string[]; invalidate(): void };
|
|
34
34
|
|
|
35
35
|
export type TransientErrorUI = {
|
|
36
36
|
setWidget(
|
package/src/tui.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -43,7 +43,7 @@ export function viewportText(
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
type ViewportComponent = {
|
|
46
|
-
render(width: number): string[];
|
|
46
|
+
render(width: number): readonly string[];
|
|
47
47
|
invalidate(): void;
|
|
48
48
|
};
|
|
49
49
|
|
|
@@ -55,7 +55,7 @@ type ViewportEntry = {
|
|
|
55
55
|
/** Raw line → line fitted to this width. */
|
|
56
56
|
lines: Map<string, string>;
|
|
57
57
|
/** Inner render output for the current text at this width. */
|
|
58
|
-
rendered: string[] | undefined;
|
|
58
|
+
rendered: readonly string[] | undefined;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
class ViewportText implements TextComponentLike, ViewportComponent {
|
|
@@ -84,7 +84,7 @@ class ViewportText implements TextComponentLike, ViewportComponent {
|
|
|
84
84
|
return this.text;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
render(width: number): string[] {
|
|
87
|
+
render(width: number): readonly string[] {
|
|
88
88
|
let entry = this.widths.get(width);
|
|
89
89
|
if (entry) {
|
|
90
90
|
// Refresh recency: Map keeps insertion order, so re-insert moves it to the end.
|
package/src/overlay-images.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { TuiMainScreen } from "@earendil-works/pi-tui";
|
|
2
|
-
|
|
3
|
-
const PATCHED = Symbol.for("@xynogen/pix-pretty:overlay-images");
|
|
4
|
-
type Compositor = {
|
|
5
|
-
hasOverlay(): boolean;
|
|
6
|
-
compositeOverlays(lines: string[], width: number, height: number): string[];
|
|
7
|
-
[PATCHED]?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/** Let the native renderer remove image placements before it draws an overlay. */
|
|
11
|
-
export function installOverlayImages(): void {
|
|
12
|
-
const prototype = Object.getPrototypeOf(TuiMainScreen.prototype) as Compositor;
|
|
13
|
-
if (prototype[PATCHED]) return;
|
|
14
|
-
const compose = prototype.compositeOverlays;
|
|
15
|
-
// ponytail: Pi skips overlay composition on image lines; suppress transcript images until upstream supports image occlusion.
|
|
16
|
-
prototype.compositeOverlays = function (lines, width, height) {
|
|
17
|
-
const background = this.hasOverlay()
|
|
18
|
-
? lines.map((line) =>
|
|
19
|
-
line.includes("\x1b_G") || line.includes("\x1b]1337;File=") ? "" : line,
|
|
20
|
-
)
|
|
21
|
-
: lines;
|
|
22
|
-
return compose.call(this, background, width, height);
|
|
23
|
-
};
|
|
24
|
-
prototype[PATCHED] = true;
|
|
25
|
-
}
|