@xynogen/pix-pretty 3.0.0 → 3.0.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/confirm.ts +7 -6
- package/src/gate-overlay.ts +13 -12
- package/src/text.ts +11 -0
package/package.json
CHANGED
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.
|
|
@@ -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/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. */
|
|
@@ -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/text.ts
CHANGED
|
@@ -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
|
+
}
|