@narumitw/pi-starship 0.55.0 → 0.55.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/README.md +21 -36
- package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
- package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
- package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
- package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
- package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
- package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
- package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
- package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
- package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
- package/dist/chunks/commands-ATILSUVK.js.map +7 -0
- package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
- package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
- package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
- package/dist/chunks/development-OUYXDPBS.js.map +7 -0
- package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
- package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
- package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
- package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
- package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
- package/dist/chunks/package-YXRZQAOV.js.map +7 -0
- package/dist/index.ts +38 -53
- package/dist/index.ts.map +2 -2
- package/package.json +60 -61
- package/skills/configuring-pi-starship/references/runtime-and-security.md +5 -1
- package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
- package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
- package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
- package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
- package/src/command-configuration.ts +267 -286
- package/src/command-contract.ts +6 -6
- package/src/command-inspector.ts +27 -27
- package/src/command-preset-picker.ts +45 -50
- package/src/command-preview.ts +153 -166
- package/src/commands.ts +588 -618
- package/src/config.ts +580 -660
- package/src/effective-config.ts +46 -48
- package/src/format/formatter.ts +211 -227
- package/src/format/style.ts +205 -216
- package/src/modules/activity.ts +74 -74
- package/src/modules/brand.ts +9 -9
- package/src/modules/cache.ts +18 -18
- package/src/modules/catalog.ts +79 -83
- package/src/modules/cloud.ts +54 -54
- package/src/modules/context.ts +27 -27
- package/src/modules/cost.ts +23 -23
- package/src/modules/deployment.ts +45 -45
- package/src/modules/development.ts +80 -81
- package/src/modules/directory.ts +89 -113
- package/src/modules/display.ts +9 -9
- package/src/modules/execution.ts +62 -69
- package/src/modules/extension-status.ts +59 -64
- package/src/modules/fill.ts +10 -10
- package/src/modules/git/branch.ts +26 -26
- package/src/modules/git/commit.ts +21 -23
- package/src/modules/git/metrics.ts +22 -22
- package/src/modules/git/runtime.ts +299 -334
- package/src/modules/git/state.ts +17 -17
- package/src/modules/git/status.ts +77 -79
- package/src/modules/git/worktree.ts +10 -12
- package/src/modules/github-pr.ts +20 -20
- package/src/modules/helpers.ts +3 -3
- package/src/modules/index.ts +21 -21
- package/src/modules/inspection.ts +101 -108
- package/src/modules/languages.ts +52 -59
- package/src/modules/model.ts +57 -67
- package/src/modules/package.ts +12 -12
- package/src/modules/provider.ts +22 -24
- package/src/modules/render.ts +124 -140
- package/src/modules/thinking.ts +27 -26
- package/src/modules/time.ts +10 -13
- package/src/modules/tokens.ts +13 -13
- package/src/modules/truncation.ts +14 -17
- package/src/modules/turn.ts +9 -9
- package/src/modules/types.ts +125 -132
- package/src/modules/workspace-helpers.ts +4 -7
- package/src/pi-starship.ts +567 -571
- package/src/presets/catalog.ts +113 -113
- package/src/runtime/cloud.ts +122 -150
- package/src/runtime/command.ts +106 -108
- package/src/runtime/deployment.ts +150 -179
- package/src/runtime/development.ts +107 -124
- package/src/runtime/execution.ts +110 -124
- package/src/runtime/github-pr.ts +223 -252
- package/src/runtime/helpers.ts +186 -199
- package/src/runtime/languages.ts +149 -180
- package/src/runtime/package.ts +74 -87
- package/src/runtime/refresh-controller.ts +82 -86
- package/src/runtime/types.ts +38 -38
- package/src/runtime/workspace.ts +108 -116
- package/src/usage.ts +40 -40
- package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
- package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
- package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
- package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
- package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
- package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
- package/dist/chunks/development-BERD42HW.js.map +0 -7
- package/dist/chunks/execution-42JTEY3N.js.map +0 -7
- package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
- package/dist/chunks/package-LG5H7BBM.js.map +0 -7
package/src/command-inspector.ts
CHANGED
|
@@ -2,40 +2,40 @@ import { stripVTControlCharacters } from "node:util";
|
|
|
2
2
|
import type { StatuslineInspection } from "./modules/inspection.js";
|
|
3
3
|
|
|
4
4
|
export function formatFooterExplanation(inspection: StatuslineInspection | undefined): string {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
if (!inspection) {
|
|
6
|
+
return safeLines([
|
|
7
|
+
"Footer inspection is unavailable until the TUI footer is ready.",
|
|
8
|
+
"No collection work was started.",
|
|
9
|
+
]);
|
|
10
|
+
}
|
|
11
|
+
if (inspection.showing.length === 0) {
|
|
12
|
+
return safeLines([
|
|
13
|
+
"No modules are currently showing.",
|
|
14
|
+
"Open Modules to inspect empty, disabled, or unreachable modules.",
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
return safeLines(
|
|
18
|
+
inspection.showing.flatMap((module, index) => [
|
|
19
|
+
...(index > 0 ? [""] : []),
|
|
20
|
+
module.name,
|
|
21
|
+
...previewLines(module.preview),
|
|
22
|
+
module.description,
|
|
23
|
+
]),
|
|
24
|
+
);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function previewLines(preview: string): string[] {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const lines = preview ? preview.split("\n") : ["(no text)"];
|
|
29
|
+
return lines.map((line, index) => `${index === 0 ? "Value: " : " "}${line}`);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function safeLines(lines: readonly string[]): string {
|
|
33
|
-
|
|
33
|
+
return lines.map(safeDisplayText).join("\n");
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
function safeDisplayText(value: string): string {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
return Array.from(stripVTControlCharacters(value), (character) => {
|
|
38
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
39
|
+
return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? "" : character;
|
|
40
|
+
}).join("");
|
|
41
41
|
}
|
|
@@ -3,60 +3,55 @@ import { runLiveChoice } from "@narumitw/pi-tui-kit";
|
|
|
3
3
|
import type { StarshipPreset } from "./presets/catalog.js";
|
|
4
4
|
|
|
5
5
|
export type PresetPickerResult =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
| { kind: "apply"; presetId: StarshipPreset["id"] }
|
|
7
|
+
| { kind: "customize"; presetId: StarshipPreset["id"] }
|
|
8
|
+
| { kind: "back" }
|
|
9
|
+
| { kind: "close" };
|
|
10
10
|
|
|
11
11
|
export interface PresetPickerOptions {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
presets: readonly StarshipPreset[];
|
|
13
|
+
activePresetId?: StarshipPreset["id"];
|
|
14
|
+
initialPresetId?: StarshipPreset["id"];
|
|
15
|
+
signal: AbortSignal;
|
|
16
|
+
isCurrent(): boolean;
|
|
17
|
+
preview(preset: StarshipPreset): void;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export async function showPresetPicker(
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
ctx: ExtensionCommandContext,
|
|
22
|
+
options: PresetPickerOptions,
|
|
23
23
|
): Promise<PresetPickerResult> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (result.kind === "shortcut") {
|
|
58
|
-
return { kind: "customize", presetId: result.itemId };
|
|
59
|
-
}
|
|
60
|
-
if (result.kind === "closed" && result.reason === "back") return { kind: "back" };
|
|
61
|
-
return { kind: "close" };
|
|
24
|
+
const current =
|
|
25
|
+
options.presets.find((preset) => preset.id === options.activePresetId)?.label ?? "Custom configuration";
|
|
26
|
+
const result = await runLiveChoice(ctx, {
|
|
27
|
+
title: `Presets · current: ${current}`,
|
|
28
|
+
items: options.presets.map((preset) => ({
|
|
29
|
+
id: preset.id,
|
|
30
|
+
label: preset.label,
|
|
31
|
+
description:
|
|
32
|
+
preset.id === options.activePresetId ? `Currently applied · ${preset.description}` : preset.description,
|
|
33
|
+
details: [`Selected: ${preset.label} · ${preset.requiresNerdFont ? "requires Nerd Font" : "font-safe"}`],
|
|
34
|
+
confirmationDisabled: preset.id === options.activePresetId,
|
|
35
|
+
confirmationDisabledReason: "Already applied; press e to customize",
|
|
36
|
+
})),
|
|
37
|
+
currentItemId: options.activePresetId,
|
|
38
|
+
initialItemId: options.initialPresetId ?? options.activePresetId,
|
|
39
|
+
viewportSize: Math.min(options.presets.length, 10),
|
|
40
|
+
hint: "back",
|
|
41
|
+
navigationLabel: "live preview",
|
|
42
|
+
confirmLabel: "apply",
|
|
43
|
+
shortcuts: [{ id: "customize", keys: ["e", "shift+e"], label: "customize" }],
|
|
44
|
+
onSelectionChange: ({ item }) => {
|
|
45
|
+
const preset = options.presets.find((candidate) => candidate.id === item.id);
|
|
46
|
+
if (preset) options.preview(preset);
|
|
47
|
+
},
|
|
48
|
+
signal: options.signal,
|
|
49
|
+
isCurrent: options.isCurrent,
|
|
50
|
+
});
|
|
51
|
+
if (result.kind === "selected") return { kind: "apply", presetId: result.itemId };
|
|
52
|
+
if (result.kind === "shortcut") {
|
|
53
|
+
return { kind: "customize", presetId: result.itemId };
|
|
54
|
+
}
|
|
55
|
+
if (result.kind === "closed" && result.reason === "back") return { kind: "back" };
|
|
56
|
+
return { kind: "close" };
|
|
62
57
|
}
|
package/src/command-preview.ts
CHANGED
|
@@ -6,199 +6,186 @@ import { runCustomInteraction } from "@narumitw/pi-tui-kit";
|
|
|
6
6
|
const RESERVED_HOST_ROWS = 3;
|
|
7
7
|
|
|
8
8
|
export interface PreviewMenuItem<Value extends string> {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
value: Value;
|
|
10
|
+
label: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export type PreviewMenuResult<Value extends string> =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
| { kind: "selected"; value: Value }
|
|
15
|
+
| { kind: "cancelled" }
|
|
16
|
+
| { kind: "closed" };
|
|
17
17
|
|
|
18
18
|
export async function showPreviewActionMenu<Value extends string>(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
ctx: ExtensionCommandContext,
|
|
20
|
+
title: string,
|
|
21
|
+
body: (width: number) => readonly string[],
|
|
22
|
+
items: readonly PreviewMenuItem<Value>[],
|
|
23
|
+
signal?: AbortSignal,
|
|
24
|
+
isCurrent: () => boolean = () => !signal?.aborted,
|
|
25
25
|
): Promise<PreviewMenuResult<Value> | undefined> {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
if (signal?.aborted || !isCurrent()) return { kind: "closed" };
|
|
27
|
+
const result = await runCustomInteraction<PreviewMenuResult<Value>>(ctx, {
|
|
28
|
+
signal,
|
|
29
|
+
isCurrent,
|
|
30
|
+
create: ({ tui, theme, keybindings, complete }) => {
|
|
31
|
+
let selectedIndex = 0;
|
|
32
|
+
let scrollOffset = 0;
|
|
33
|
+
let lastMaximumScroll = 0;
|
|
34
|
+
let lastViewportSize = 1;
|
|
35
|
+
let disposed = false;
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
const requestRender = () => {
|
|
38
|
+
if (!disposed) tui.requestRender();
|
|
39
|
+
};
|
|
40
|
+
const moveSelection = (delta: number) => {
|
|
41
|
+
if (items.length === 0) return;
|
|
42
|
+
selectedIndex = (selectedIndex + delta + items.length) % items.length;
|
|
43
|
+
requestRender();
|
|
44
|
+
};
|
|
45
|
+
const movePreview = (offset: number) => {
|
|
46
|
+
scrollOffset = Math.max(0, Math.min(offset, lastMaximumScroll));
|
|
47
|
+
requestRender();
|
|
48
|
+
};
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
if (result.kind === "completed") return result.value;
|
|
119
|
-
if (result.kind === "error") throw result.error;
|
|
120
|
-
if (result.kind === "stale" && (signal?.aborted || !isCurrent())) return { kind: "closed" };
|
|
121
|
-
return undefined;
|
|
50
|
+
return {
|
|
51
|
+
render(width: number): string[] {
|
|
52
|
+
const safeWidth = Math.max(1, width);
|
|
53
|
+
const terminalRows = Number.isFinite(tui.terminal.rows) ? Math.floor(tui.terminal.rows) : 24;
|
|
54
|
+
const availableRows = Math.max(1, terminalRows - RESERVED_HOST_ROWS);
|
|
55
|
+
const bodyLines = body(safeWidth).flatMap((line) => (line ? wrapTextWithAnsi(line, safeWidth) : [""]));
|
|
56
|
+
const layout = allocateLayout(availableRows, items.length, bodyLines.length);
|
|
57
|
+
lastViewportSize = layout.previewRows;
|
|
58
|
+
lastMaximumScroll = Math.max(0, bodyLines.length - layout.previewRows);
|
|
59
|
+
scrollOffset = Math.max(0, Math.min(scrollOffset, lastMaximumScroll));
|
|
60
|
+
const actionStart = actionWindowStart(selectedIndex, items.length, layout.actionRows);
|
|
61
|
+
const actionLines = items.slice(actionStart, actionStart + layout.actionRows).map((item, index) => {
|
|
62
|
+
const absoluteIndex = actionStart + index;
|
|
63
|
+
const prefix = absoluteIndex === selectedIndex ? "→ " : " ";
|
|
64
|
+
return theme.fg(
|
|
65
|
+
absoluteIndex === selectedIndex ? "accent" : "text",
|
|
66
|
+
`${prefix}${safeDisplayText(item.label)}`,
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
const position = layout.positionRows
|
|
70
|
+
? [theme.fg("dim", previewPosition(scrollOffset, layout.previewRows, bodyLines.length))]
|
|
71
|
+
: [];
|
|
72
|
+
const lines = [
|
|
73
|
+
...(layout.titleRows ? [theme.fg("accent", theme.bold(safeDisplayText(title)))] : []),
|
|
74
|
+
...bodyLines.slice(scrollOffset, scrollOffset + layout.previewRows),
|
|
75
|
+
...position,
|
|
76
|
+
...actionLines,
|
|
77
|
+
...(layout.hintRows ? [theme.fg("dim", previewHint(keybindings))] : []),
|
|
78
|
+
];
|
|
79
|
+
return lines.map((line) => truncateToWidth(line, safeWidth, ""));
|
|
80
|
+
},
|
|
81
|
+
invalidate() {},
|
|
82
|
+
handleInput(data: string) {
|
|
83
|
+
if (disposed) return;
|
|
84
|
+
if (matchesKey(data, Key.ctrl("c"))) {
|
|
85
|
+
complete({ kind: "closed" });
|
|
86
|
+
} else if (keybindings.matches(data, "tui.select.cancel")) {
|
|
87
|
+
complete({ kind: "cancelled" });
|
|
88
|
+
} else if (keybindings.matches(data, "tui.select.up")) {
|
|
89
|
+
moveSelection(-1);
|
|
90
|
+
} else if (keybindings.matches(data, "tui.select.down")) {
|
|
91
|
+
moveSelection(1);
|
|
92
|
+
} else if (keybindings.matches(data, "tui.select.pageUp")) {
|
|
93
|
+
movePreview(scrollOffset - lastViewportSize);
|
|
94
|
+
} else if (keybindings.matches(data, "tui.select.pageDown")) {
|
|
95
|
+
movePreview(scrollOffset + lastViewportSize);
|
|
96
|
+
} else if (matchesKey(data, Key.home)) {
|
|
97
|
+
movePreview(0);
|
|
98
|
+
} else if (matchesKey(data, Key.end)) {
|
|
99
|
+
movePreview(lastMaximumScroll);
|
|
100
|
+
} else if (keybindings.matches(data, "tui.select.confirm")) {
|
|
101
|
+
const item = items[selectedIndex];
|
|
102
|
+
if (item) complete({ kind: "selected", value: item.value });
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
dispose() {
|
|
106
|
+
if (disposed) return;
|
|
107
|
+
disposed = true;
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
if (result.kind === "completed") return result.value;
|
|
113
|
+
if (result.kind === "error") throw result.error;
|
|
114
|
+
if (result.kind === "stale" && (signal?.aborted || !isCurrent())) return { kind: "closed" };
|
|
115
|
+
return undefined;
|
|
122
116
|
}
|
|
123
117
|
|
|
124
118
|
interface PreviewLayout {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
titleRows: number;
|
|
120
|
+
previewRows: number;
|
|
121
|
+
positionRows: number;
|
|
122
|
+
actionRows: number;
|
|
123
|
+
hintRows: number;
|
|
130
124
|
}
|
|
131
125
|
|
|
132
|
-
function allocateLayout(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
availableRows - titleRows - hintRows - minimumPreviewRows,
|
|
146
|
-
);
|
|
147
|
-
const actionRows = Math.min(Math.max(1, actionCount), availableActionRows);
|
|
148
|
-
let previewRows = Math.max(0, availableRows - titleRows - hintRows - actionRows);
|
|
149
|
-
const positionRows = previewRows >= 2 && bodyLineCount > previewRows ? 1 : 0;
|
|
150
|
-
previewRows -= positionRows;
|
|
151
|
-
return { titleRows, previewRows, positionRows, actionRows, hintRows };
|
|
126
|
+
function allocateLayout(availableRows: number, actionCount: number, bodyLineCount: number): PreviewLayout {
|
|
127
|
+
if (availableRows === 1) {
|
|
128
|
+
return { titleRows: 0, previewRows: 0, positionRows: 0, actionRows: 1, hintRows: 0 };
|
|
129
|
+
}
|
|
130
|
+
const titleRows = availableRows >= 3 ? 1 : 0;
|
|
131
|
+
const hintRows = availableRows >= 3 ? 1 : 0;
|
|
132
|
+
const minimumPreviewRows = bodyLineCount > 0 && availableRows >= 4 ? 1 : 0;
|
|
133
|
+
const availableActionRows = Math.max(1, availableRows - titleRows - hintRows - minimumPreviewRows);
|
|
134
|
+
const actionRows = Math.min(Math.max(1, actionCount), availableActionRows);
|
|
135
|
+
let previewRows = Math.max(0, availableRows - titleRows - hintRows - actionRows);
|
|
136
|
+
const positionRows = previewRows >= 2 && bodyLineCount > previewRows ? 1 : 0;
|
|
137
|
+
previewRows -= positionRows;
|
|
138
|
+
return { titleRows, previewRows, positionRows, actionRows, hintRows };
|
|
152
139
|
}
|
|
153
140
|
|
|
154
141
|
function actionWindowStart(selectedIndex: number, itemCount: number, viewportSize: number): number {
|
|
155
|
-
|
|
156
|
-
|
|
142
|
+
if (itemCount <= viewportSize) return 0;
|
|
143
|
+
return Math.max(0, Math.min(selectedIndex, itemCount - viewportSize));
|
|
157
144
|
}
|
|
158
145
|
|
|
159
146
|
function previewPosition(offset: number, viewportSize: number, lineCount: number): string {
|
|
160
|
-
|
|
161
|
-
|
|
147
|
+
if (lineCount === 0) return "0/0";
|
|
148
|
+
return `${offset + 1}-${Math.min(lineCount, offset + viewportSize)}/${lineCount}`;
|
|
162
149
|
}
|
|
163
150
|
|
|
164
151
|
function previewHint(keybindings: Pick<KeybindingsManager, "getKeys">): string {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
152
|
+
const up = bindingText(keybindings, "tui.select.up");
|
|
153
|
+
const down = bindingText(keybindings, "tui.select.down");
|
|
154
|
+
const confirm = bindingText(keybindings, "tui.select.confirm");
|
|
155
|
+
const cancel = bindingText(keybindings, "tui.select.cancel", "ctrl+c");
|
|
156
|
+
const pageUp = bindingText(keybindings, "tui.select.pageUp");
|
|
157
|
+
const pageDown = bindingText(keybindings, "tui.select.pageDown");
|
|
158
|
+
return [
|
|
159
|
+
...(up || down ? [`${[up, down].filter(Boolean).join("/")} navigate`] : []),
|
|
160
|
+
...(confirm ? [`${confirm} select`] : []),
|
|
161
|
+
...(cancel ? [`${cancel} discard`] : []),
|
|
162
|
+
"ctrl+c close",
|
|
163
|
+
...(pageUp || pageDown ? [`${[pageUp, pageDown].filter(Boolean).join("/")} preview`] : []),
|
|
164
|
+
].join(" • ");
|
|
178
165
|
}
|
|
179
166
|
|
|
180
167
|
function bindingText(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
168
|
+
keybindings: Pick<KeybindingsManager, "getKeys">,
|
|
169
|
+
binding: Parameters<KeybindingsManager["getKeys"]>[0],
|
|
170
|
+
excluded?: string,
|
|
184
171
|
): string {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
172
|
+
return keybindings
|
|
173
|
+
.getKeys(binding)
|
|
174
|
+
.filter((key) => key !== excluded)
|
|
175
|
+
.map((key) => {
|
|
176
|
+
if (key === "up") return "↑";
|
|
177
|
+
if (key === "down") return "↓";
|
|
178
|
+
if (key === "escape") return "esc";
|
|
179
|
+
if (key === "return") return "enter";
|
|
180
|
+
return safeDisplayText(key);
|
|
181
|
+
})
|
|
182
|
+
.join("/");
|
|
196
183
|
}
|
|
197
184
|
|
|
198
185
|
function safeDisplayText(value: string): string {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
186
|
+
return Array.from(stripVTControlCharacters(value), (character) => {
|
|
187
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
188
|
+
const control = codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f);
|
|
189
|
+
return control ? "" : character;
|
|
190
|
+
}).join("");
|
|
204
191
|
}
|