@narumitw/pi-starship 0.50.0 → 0.50.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/command-inspector.ts +19 -176
- package/src/commands.ts +12 -9
package/package.json
CHANGED
package/src/command-inspector.ts
CHANGED
|
@@ -1,108 +1,27 @@
|
|
|
1
1
|
import { stripVTControlCharacters } from "node:util";
|
|
2
|
-
import type { ExtensionCommandContext, KeybindingsManager } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import { Key, matchesKey, truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
4
2
|
import type { StatuslineInspection } from "./modules/inspection.js";
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export type InspectorResult = { kind: "back" } | { kind: "close" };
|
|
9
|
-
|
|
10
|
-
export function showFooterExplanation(
|
|
11
|
-
ctx: ExtensionCommandContext,
|
|
12
|
-
inspection: StatuslineInspection | undefined,
|
|
13
|
-
signal?: AbortSignal,
|
|
14
|
-
): Promise<InspectorResult | undefined> {
|
|
15
|
-
if (signal?.aborted) return Promise.resolve({ kind: "close" });
|
|
16
|
-
return ctx.ui.custom<InspectorResult | undefined>((tui, theme, keybindings, done) => {
|
|
17
|
-
let scrollOffset = 0;
|
|
18
|
-
let lastMaximumScroll = 0;
|
|
19
|
-
let lastViewportSize = 1;
|
|
20
|
-
let disposed = false;
|
|
21
|
-
let settled = false;
|
|
22
|
-
let deferredAbort: ReturnType<typeof setImmediate> | undefined;
|
|
23
|
-
const finish = (result: InspectorResult) => {
|
|
24
|
-
if (disposed || settled) return;
|
|
25
|
-
settled = true;
|
|
26
|
-
done(result);
|
|
27
|
-
};
|
|
28
|
-
const closeForAbort = () => finish({ kind: "close" });
|
|
29
|
-
signal?.addEventListener("abort", closeForAbort, { once: true });
|
|
30
|
-
if (signal?.aborted) deferredAbort = setImmediate(closeForAbort);
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
focused: false,
|
|
34
|
-
render(width: number): string[] {
|
|
35
|
-
const safeWidth = Math.max(1, width);
|
|
36
|
-
const availableRows = componentRows(tui.terminal.rows);
|
|
37
|
-
const content = explanationLines(inspection, safeWidth);
|
|
38
|
-
const layout = detailLayout(availableRows, content.length);
|
|
39
|
-
lastViewportSize = layout.contentRows;
|
|
40
|
-
lastMaximumScroll = Math.max(0, content.length - layout.contentRows);
|
|
41
|
-
scrollOffset = clamp(scrollOffset, 0, lastMaximumScroll);
|
|
42
|
-
const lines = [
|
|
43
|
-
...(layout.titleRows ? [theme.fg("accent", theme.bold("Explain footer"))] : []),
|
|
44
|
-
...content.slice(scrollOffset, scrollOffset + layout.contentRows),
|
|
45
|
-
...(layout.positionRows
|
|
46
|
-
? [theme.fg("dim", positionText(scrollOffset, layout.contentRows, content.length))]
|
|
47
|
-
: []),
|
|
48
|
-
...(layout.hintRows ? [theme.fg("dim", detailHint(keybindings, "back"))] : []),
|
|
49
|
-
];
|
|
50
|
-
return boundedLines(lines, safeWidth, availableRows);
|
|
51
|
-
},
|
|
52
|
-
invalidate() {},
|
|
53
|
-
handleInput(data: string) {
|
|
54
|
-
if (disposed || settled) return;
|
|
55
|
-
if (matchesKey(data, Key.ctrl("c"))) finish({ kind: "close" });
|
|
56
|
-
else if (keybindings.matches(data, "tui.select.cancel")) finish({ kind: "back" });
|
|
57
|
-
else if (keybindings.matches(data, "tui.select.up")) {
|
|
58
|
-
scrollOffset = clamp(scrollOffset - 1, 0, lastMaximumScroll);
|
|
59
|
-
} else if (keybindings.matches(data, "tui.select.down")) {
|
|
60
|
-
scrollOffset = clamp(scrollOffset + 1, 0, lastMaximumScroll);
|
|
61
|
-
} else if (keybindings.matches(data, "tui.select.pageUp")) {
|
|
62
|
-
scrollOffset = clamp(scrollOffset - lastViewportSize, 0, lastMaximumScroll);
|
|
63
|
-
} else if (keybindings.matches(data, "tui.select.pageDown")) {
|
|
64
|
-
scrollOffset = clamp(scrollOffset + lastViewportSize, 0, lastMaximumScroll);
|
|
65
|
-
} else if (matchesKey(data, Key.home)) scrollOffset = 0;
|
|
66
|
-
else if (matchesKey(data, Key.end)) scrollOffset = lastMaximumScroll;
|
|
67
|
-
tui.requestRender();
|
|
68
|
-
},
|
|
69
|
-
dispose() {
|
|
70
|
-
if (disposed) return;
|
|
71
|
-
disposed = true;
|
|
72
|
-
if (deferredAbort) clearImmediate(deferredAbort);
|
|
73
|
-
deferredAbort = undefined;
|
|
74
|
-
signal?.removeEventListener("abort", closeForAbort);
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function explanationLines(inspection: StatuslineInspection | undefined, width: number): string[] {
|
|
4
|
+
export function formatFooterExplanation(inspection: StatuslineInspection | undefined): string {
|
|
81
5
|
if (!inspection) {
|
|
82
|
-
return
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
],
|
|
87
|
-
width,
|
|
88
|
-
);
|
|
6
|
+
return safeLines([
|
|
7
|
+
"Footer inspection is unavailable until the TUI footer is ready.",
|
|
8
|
+
"No collection work was started.",
|
|
9
|
+
]);
|
|
89
10
|
}
|
|
90
11
|
if (inspection.showing.length === 0) {
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
],
|
|
96
|
-
width,
|
|
97
|
-
);
|
|
12
|
+
return safeLines([
|
|
13
|
+
"No modules are currently showing.",
|
|
14
|
+
"Open Modules to inspect empty, disabled, or unreachable modules.",
|
|
15
|
+
]);
|
|
98
16
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
17
|
+
return safeLines(
|
|
18
|
+
inspection.showing.flatMap((module, index) => [
|
|
19
|
+
...(index > 0 ? [""] : []),
|
|
20
|
+
module.name,
|
|
21
|
+
...previewLines(module.preview),
|
|
22
|
+
module.description,
|
|
23
|
+
]),
|
|
24
|
+
);
|
|
106
25
|
}
|
|
107
26
|
|
|
108
27
|
function previewLines(preview: string): string[] {
|
|
@@ -110,80 +29,8 @@ function previewLines(preview: string): string[] {
|
|
|
110
29
|
return lines.map((line, index) => `${index === 0 ? "Value: " : " "}${line}`);
|
|
111
30
|
}
|
|
112
31
|
|
|
113
|
-
function
|
|
114
|
-
return lines.
|
|
115
|
-
const safe = safeDisplayText(line);
|
|
116
|
-
return safe ? wrapTextWithAnsi(safe, width) : [""];
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
interface DetailLayout {
|
|
121
|
-
titleRows: number;
|
|
122
|
-
contentRows: number;
|
|
123
|
-
positionRows: number;
|
|
124
|
-
hintRows: number;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function detailLayout(availableRows: number, contentLength: number): DetailLayout {
|
|
128
|
-
if (availableRows === 1) {
|
|
129
|
-
return { titleRows: 0, contentRows: 1, positionRows: 0, hintRows: 0 };
|
|
130
|
-
}
|
|
131
|
-
const titleRows = availableRows >= 4 ? 1 : 0;
|
|
132
|
-
const hintRows = availableRows >= 3 ? 1 : 0;
|
|
133
|
-
let contentRows = Math.max(1, availableRows - titleRows - hintRows);
|
|
134
|
-
const positionRows = contentLength > contentRows && contentRows >= 2 ? 1 : 0;
|
|
135
|
-
contentRows -= positionRows;
|
|
136
|
-
return { titleRows, contentRows, positionRows, hintRows };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function componentRows(rows: number): number {
|
|
140
|
-
const terminalRows = Number.isFinite(rows) ? Math.floor(rows) : 24;
|
|
141
|
-
return Math.max(1, terminalRows - RESERVED_HOST_ROWS);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function positionText(offset: number, viewportSize: number, itemCount: number): string {
|
|
145
|
-
if (itemCount === 0) return "0/0";
|
|
146
|
-
return `${offset + 1}-${Math.min(itemCount, offset + viewportSize)}/${itemCount}`;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function boundedLines(lines: readonly string[], width: number, rows: number): string[] {
|
|
150
|
-
return lines.slice(0, rows).map((line) => truncateToWidth(line, width, ""));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function detailHint(
|
|
154
|
-
keybindings: Pick<KeybindingsManager, "getKeys">,
|
|
155
|
-
destination: "back" | "close",
|
|
156
|
-
): string {
|
|
157
|
-
const up = bindingText(keybindings, "tui.select.up");
|
|
158
|
-
const down = bindingText(keybindings, "tui.select.down");
|
|
159
|
-
const cancel = bindingText(keybindings, "tui.select.cancel", "ctrl+c");
|
|
160
|
-
const pageUp = bindingText(keybindings, "tui.select.pageUp");
|
|
161
|
-
const pageDown = bindingText(keybindings, "tui.select.pageDown");
|
|
162
|
-
return [
|
|
163
|
-
...(up || down ? [`${[up, down].filter(Boolean).join("/")} scroll`] : []),
|
|
164
|
-
...(pageUp || pageDown ? [`${[pageUp, pageDown].filter(Boolean).join("/")} page`] : []),
|
|
165
|
-
...(cancel ? [`${cancel} ${destination}`] : []),
|
|
166
|
-
"ctrl+c close",
|
|
167
|
-
].join(" • ");
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function bindingText(
|
|
171
|
-
keybindings: Pick<KeybindingsManager, "getKeys">,
|
|
172
|
-
binding: Parameters<KeybindingsManager["getKeys"]>[0],
|
|
173
|
-
excluded?: string,
|
|
174
|
-
): string {
|
|
175
|
-
return keybindings
|
|
176
|
-
.getKeys(binding)
|
|
177
|
-
.filter((key) => key !== excluded)
|
|
178
|
-
.map((key) => {
|
|
179
|
-
if (key === "up") return "↑";
|
|
180
|
-
if (key === "down") return "↓";
|
|
181
|
-
if (key === "escape") return "esc";
|
|
182
|
-
if (key === "return") return "enter";
|
|
183
|
-
return safeDisplayText(key);
|
|
184
|
-
})
|
|
185
|
-
.filter(Boolean)
|
|
186
|
-
.join("/");
|
|
32
|
+
function safeLines(lines: readonly string[]): string {
|
|
33
|
+
return lines.map(safeDisplayText).join("\n");
|
|
187
34
|
}
|
|
188
35
|
|
|
189
36
|
function safeDisplayText(value: string): string {
|
|
@@ -192,7 +39,3 @@ function safeDisplayText(value: string): string {
|
|
|
192
39
|
return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? "" : character;
|
|
193
40
|
}).join("");
|
|
194
41
|
}
|
|
195
|
-
|
|
196
|
-
function clamp(value: number, minimum: number, maximum: number): number {
|
|
197
|
-
return Math.max(minimum, Math.min(value, maximum));
|
|
198
|
-
}
|
package/src/commands.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
3
3
|
import { completeStarshipArguments, STARSHIP_SUBCOMMANDS } from "./command-contract.js";
|
|
4
|
-
import {
|
|
4
|
+
import { formatFooterExplanation } from "./command-inspector.js";
|
|
5
5
|
import { showPresetPicker } from "./command-preset-picker.js";
|
|
6
6
|
import { type PreviewMenuResult, showPreviewActionMenu } from "./command-preview.js";
|
|
7
7
|
import {
|
|
@@ -114,8 +114,8 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
114
114
|
signal: fallbackController.signal,
|
|
115
115
|
isCurrent: () => !fallbackController.signal.aborted,
|
|
116
116
|
};
|
|
117
|
-
type Screen = "main" | "modules" | "configuration" | "help";
|
|
118
|
-
type Action = "customize" | "presets" | "
|
|
117
|
+
type Screen = "main" | "explain" | "modules" | "configuration" | "help";
|
|
118
|
+
type Action = "customize" | "presets" | "restore";
|
|
119
119
|
const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({
|
|
120
120
|
start: "main",
|
|
121
121
|
screens: {
|
|
@@ -143,7 +143,7 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
143
143
|
id: MAIN_ACTIONS.explain,
|
|
144
144
|
label: "Explain footer",
|
|
145
145
|
description: "Why each visible module appears",
|
|
146
|
-
|
|
146
|
+
to: "explain",
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
149
|
id: MAIN_ACTIONS.modules,
|
|
@@ -174,6 +174,14 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
174
174
|
hint: "close",
|
|
175
175
|
};
|
|
176
176
|
},
|
|
177
|
+
explain: () => ({
|
|
178
|
+
kind: "review",
|
|
179
|
+
title: "Explain footer",
|
|
180
|
+
content: formatFooterExplanation(options.getInspection?.()),
|
|
181
|
+
format: { kind: "text" },
|
|
182
|
+
viewportSize: "adaptive",
|
|
183
|
+
hint: "back",
|
|
184
|
+
}),
|
|
177
185
|
modules: () => {
|
|
178
186
|
const inspection =
|
|
179
187
|
options.getInspection?.() ?? inspectUnavailableModules(options.getLoaded().config);
|
|
@@ -237,11 +245,6 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
237
245
|
const result = await editSettings(ctx, options);
|
|
238
246
|
return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
|
|
239
247
|
},
|
|
240
|
-
explain: async () => {
|
|
241
|
-
const result = await showFooterExplanation(ctx, options.getInspection?.(), owner.signal);
|
|
242
|
-
if (!isCurrentOwner(owner)) return { kind: "stay" };
|
|
243
|
-
return result?.kind === "back" ? { kind: "stay" } : { kind: "close" };
|
|
244
|
-
},
|
|
245
248
|
presets: async () => {
|
|
246
249
|
const result = await choosePreset(ctx, options, owner);
|
|
247
250
|
return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
|