@narumitw/pi-starship 0.44.0 → 0.45.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/README.md +188 -65
- package/package.json +2 -2
- package/src/command-inspector.ts +470 -0
- package/src/command-preview.ts +206 -0
- package/src/commands.ts +168 -158
- package/src/config.ts +177 -68
- package/src/format/style.ts +64 -45
- package/src/modules/activity.ts +1 -1
- package/src/modules/brand.ts +1 -1
- package/src/modules/cache.ts +1 -1
- package/src/modules/catalog.ts +62 -3
- package/src/modules/context.ts +13 -1
- package/src/modules/cost.ts +12 -1
- package/src/modules/development.ts +1 -1
- package/src/modules/directory.ts +1 -1
- package/src/modules/display.ts +14 -0
- package/src/modules/execution.ts +12 -1
- package/src/modules/extension-status.ts +1 -1
- package/src/modules/fill.ts +1 -1
- package/src/modules/git/branch.ts +1 -1
- package/src/modules/git/commit.ts +1 -1
- package/src/modules/git/metrics.ts +8 -2
- package/src/modules/git/state.ts +1 -1
- package/src/modules/git/status.ts +1 -1
- package/src/modules/git/worktree.ts +1 -1
- package/src/modules/github-pr.ts +1 -1
- package/src/modules/index.ts +13 -1
- package/src/modules/inspection.ts +138 -0
- package/src/modules/model.ts +1 -1
- package/src/modules/provider.ts +1 -1
- package/src/modules/render.ts +22 -3
- package/src/modules/thinking.ts +1 -1
- package/src/modules/time.ts +1 -1
- package/src/modules/tokens.ts +1 -1
- package/src/modules/turn.ts +1 -1
- package/src/modules/types.ts +19 -0
- package/src/pi-starship.ts +21 -0
- package/src/runtime/execution.ts +15 -3
- package/src/runtime/types.ts +2 -0
- package/src/runtime/workspace.ts +21 -7
package/src/commands.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
3
|
-
type AutocompleteItem,
|
|
4
|
-
type SelectItem,
|
|
5
|
-
SelectList,
|
|
6
|
-
truncateToWidth,
|
|
7
|
-
wrapTextWithAnsi,
|
|
8
|
-
} from "@earendil-works/pi-tui";
|
|
2
|
+
import type { AutocompleteItem } from "@earendil-works/pi-tui";
|
|
9
3
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
4
|
+
import { showFooterExplanation, showModuleBrowser } from "./command-inspector.js";
|
|
5
|
+
import { type PreviewMenuResult, showPreviewActionMenu } from "./command-preview.js";
|
|
10
6
|
import {
|
|
11
7
|
atomicRestoreConfigDocument,
|
|
12
8
|
atomicSaveConfigDocument,
|
|
@@ -15,6 +11,7 @@ import {
|
|
|
15
11
|
removeConfigDocumentIfMatches,
|
|
16
12
|
validateConfigDocument,
|
|
17
13
|
} from "./config.js";
|
|
14
|
+
import { inspectUnavailableModules, type StatuslineInspection } from "./modules/inspection.js";
|
|
18
15
|
|
|
19
16
|
const SUBCOMMANDS: AutocompleteItem[] = [
|
|
20
17
|
{ value: "settings", label: "settings", description: "Customize the footer TOML" },
|
|
@@ -24,15 +21,11 @@ const SUBCOMMANDS: AutocompleteItem[] = [
|
|
|
24
21
|
|
|
25
22
|
const MAIN_ACTIONS = {
|
|
26
23
|
customize: "customize",
|
|
27
|
-
|
|
24
|
+
explain: "explain",
|
|
25
|
+
modules: "modules",
|
|
26
|
+
configuration: "configuration",
|
|
28
27
|
help: "help",
|
|
29
|
-
advanced: "advanced",
|
|
30
|
-
} as const;
|
|
31
|
-
|
|
32
|
-
const ADVANCED_ACTIONS = {
|
|
33
|
-
details: "details",
|
|
34
28
|
restore: "restore",
|
|
35
|
-
back: "back",
|
|
36
29
|
} as const;
|
|
37
30
|
|
|
38
31
|
const PREVIEW_ACTIONS = {
|
|
@@ -43,6 +36,7 @@ const PREVIEW_ACTIONS = {
|
|
|
43
36
|
|
|
44
37
|
export interface StarshipCommandOptions {
|
|
45
38
|
getLoaded(): LoadedStarshipConfig;
|
|
39
|
+
getInspection?(): StatuslineInspection | undefined;
|
|
46
40
|
apply(loaded: LoadedStarshipConfig, ctx: ExtensionCommandContext): void;
|
|
47
41
|
settingsPath: string;
|
|
48
42
|
renderPreview?(
|
|
@@ -56,10 +50,6 @@ export interface StarshipCommandOptions {
|
|
|
56
50
|
getMenuOwner?(): { signal: AbortSignal; isCurrent(): boolean };
|
|
57
51
|
}
|
|
58
52
|
|
|
59
|
-
interface MenuItem extends SelectItem {
|
|
60
|
-
value: string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
53
|
interface WorkflowOwner {
|
|
64
54
|
signal: AbortSignal;
|
|
65
55
|
isCurrent(): boolean;
|
|
@@ -81,8 +71,19 @@ export function registerStarshipCommand(pi: ExtensionAPI, options: StarshipComma
|
|
|
81
71
|
return;
|
|
82
72
|
}
|
|
83
73
|
|
|
84
|
-
const subcommand = normalized.split(/\s+/u)
|
|
85
|
-
|
|
74
|
+
const [subcommand = "", ...trailing] = normalized.split(/\s+/u);
|
|
75
|
+
const route = subcommand.toLowerCase();
|
|
76
|
+
if (trailing.length > 0 || !SUBCOMMANDS.some((item) => item.value === route)) {
|
|
77
|
+
if (canNotify(ctx)) {
|
|
78
|
+
const reason =
|
|
79
|
+
trailing.length > 0
|
|
80
|
+
? `Unexpected arguments for /starship ${safeText(route)}.`
|
|
81
|
+
: `Unknown /starship subcommand: ${safeText(route)}.`;
|
|
82
|
+
ctx.ui.notify(`${reason} Usage: /starship [settings|status|help]`, "warning");
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
switch (route) {
|
|
86
87
|
case "settings":
|
|
87
88
|
await editSettings(ctx, options);
|
|
88
89
|
return;
|
|
@@ -92,10 +93,6 @@ export function registerStarshipCommand(pi: ExtensionAPI, options: StarshipComma
|
|
|
92
93
|
case "help":
|
|
93
94
|
showHelp(ctx, options.settingsPath);
|
|
94
95
|
return;
|
|
95
|
-
default:
|
|
96
|
-
if (canNotify(ctx)) {
|
|
97
|
-
ctx.ui.notify(`Unknown /starship subcommand: ${subcommand}`, "warning");
|
|
98
|
-
}
|
|
99
96
|
}
|
|
100
97
|
},
|
|
101
98
|
});
|
|
@@ -107,94 +104,69 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
107
104
|
signal: fallbackController.signal,
|
|
108
105
|
isCurrent: () => !fallbackController.signal.aborted,
|
|
109
106
|
};
|
|
110
|
-
type Screen = "main" | "
|
|
111
|
-
type Action = "customize" | "
|
|
107
|
+
type Screen = "main" | "configuration" | "help";
|
|
108
|
+
type Action = "customize" | "explain" | "modules" | "restore";
|
|
112
109
|
const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({
|
|
113
110
|
start: "main",
|
|
114
111
|
screens: {
|
|
115
112
|
main: () => {
|
|
116
113
|
const loaded = options.getLoaded();
|
|
117
|
-
const
|
|
118
|
-
const health = configurationHealth(loaded);
|
|
114
|
+
const presentation = configurationPresentation(loaded);
|
|
119
115
|
return {
|
|
120
116
|
kind: "actions",
|
|
121
117
|
title: "pi-starship",
|
|
122
|
-
lines: [`${state} · ${health}`],
|
|
118
|
+
lines: [`${presentation.state} · ${presentation.health}`],
|
|
123
119
|
items: [
|
|
124
120
|
{
|
|
125
121
|
id: MAIN_ACTIONS.customize,
|
|
126
122
|
label: "Customize footer",
|
|
127
|
-
description: `${state} · preview before applying`,
|
|
123
|
+
description: `${presentation.state} · preview before applying`,
|
|
128
124
|
action: "customize",
|
|
129
125
|
},
|
|
130
126
|
{
|
|
131
|
-
id: MAIN_ACTIONS.
|
|
132
|
-
label: "
|
|
133
|
-
description:
|
|
134
|
-
|
|
127
|
+
id: MAIN_ACTIONS.explain,
|
|
128
|
+
label: "Explain footer",
|
|
129
|
+
description: "Why each visible module appears",
|
|
130
|
+
action: "explain",
|
|
135
131
|
},
|
|
136
132
|
{
|
|
137
|
-
id: MAIN_ACTIONS.
|
|
138
|
-
label: "
|
|
139
|
-
description: "
|
|
140
|
-
|
|
133
|
+
id: MAIN_ACTIONS.modules,
|
|
134
|
+
label: "Modules",
|
|
135
|
+
description: "Browse supported modules and current states",
|
|
136
|
+
action: "modules",
|
|
141
137
|
},
|
|
142
138
|
{
|
|
143
|
-
id: MAIN_ACTIONS.
|
|
144
|
-
label: "
|
|
145
|
-
description:
|
|
146
|
-
to: "
|
|
139
|
+
id: MAIN_ACTIONS.configuration,
|
|
140
|
+
label: "Configuration",
|
|
141
|
+
description: presentation.health,
|
|
142
|
+
to: "configuration",
|
|
147
143
|
},
|
|
148
|
-
],
|
|
149
|
-
hint: "close",
|
|
150
|
-
};
|
|
151
|
-
},
|
|
152
|
-
advanced: () => {
|
|
153
|
-
const loaded = options.getLoaded();
|
|
154
|
-
const alreadyBuiltIn = loaded.rawDocument === BUILT_IN_EXAMPLE;
|
|
155
|
-
return {
|
|
156
|
-
kind: "actions",
|
|
157
|
-
title: "Advanced",
|
|
158
|
-
lines: [configurationState(loaded)],
|
|
159
|
-
items: [
|
|
160
144
|
{
|
|
161
|
-
id:
|
|
162
|
-
label: "
|
|
163
|
-
description:
|
|
164
|
-
to: "
|
|
145
|
+
id: MAIN_ACTIONS.help,
|
|
146
|
+
label: "Help",
|
|
147
|
+
description: "Formats, modules, and commands",
|
|
148
|
+
to: "help",
|
|
165
149
|
},
|
|
166
150
|
{
|
|
167
|
-
id:
|
|
168
|
-
label: "Restore built-in",
|
|
169
|
-
description:
|
|
170
|
-
|
|
171
|
-
: "Preview before replacing the document",
|
|
151
|
+
id: MAIN_ACTIONS.restore,
|
|
152
|
+
label: "Restore built-in…",
|
|
153
|
+
description: presentation.restoreDescription,
|
|
154
|
+
disabled: presentation.restoreDisabled,
|
|
172
155
|
action: "restore",
|
|
173
156
|
},
|
|
174
|
-
{
|
|
175
|
-
id: ADVANCED_ACTIONS.back,
|
|
176
|
-
label: "Back",
|
|
177
|
-
description: "Return to pi-starship",
|
|
178
|
-
action: "back",
|
|
179
|
-
},
|
|
180
157
|
],
|
|
181
|
-
hint: "
|
|
158
|
+
hint: "close",
|
|
182
159
|
};
|
|
183
160
|
},
|
|
184
|
-
|
|
185
|
-
kind: "detail",
|
|
186
|
-
title: "Configuration health",
|
|
187
|
-
lines: diagnosticLines(options.getLoaded(), false),
|
|
188
|
-
hint: "back",
|
|
189
|
-
}),
|
|
190
|
-
details: () => {
|
|
161
|
+
configuration: () => {
|
|
191
162
|
const loaded = options.getLoaded();
|
|
163
|
+
const presentation = configurationPresentation(loaded);
|
|
192
164
|
return {
|
|
193
165
|
kind: "detail",
|
|
194
|
-
title: "Configuration
|
|
166
|
+
title: "Configuration",
|
|
195
167
|
lines: [
|
|
196
|
-
`State: ${
|
|
197
|
-
`Source: ${
|
|
168
|
+
`State: ${presentation.state}`,
|
|
169
|
+
`Source: ${presentation.source}`,
|
|
198
170
|
`Path: ${safeText(options.settingsPath)}`,
|
|
199
171
|
...diagnosticLines(loaded, true),
|
|
200
172
|
],
|
|
@@ -206,7 +178,9 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
206
178
|
title: "pi-starship help",
|
|
207
179
|
lines: [
|
|
208
180
|
"Customize footer opens the TOML editor, then previews and confirms before saving.",
|
|
209
|
-
"
|
|
181
|
+
"Explain footer breaks down the modules currently showing from the existing snapshot.",
|
|
182
|
+
"Modules searches every supported module and explains its current read-only state.",
|
|
183
|
+
"Configuration explains state, source, path, and warnings without changing the footer.",
|
|
210
184
|
`Settings: ${safeText(options.settingsPath)}`,
|
|
211
185
|
"Docs: https://github.com/narumiruna/pi-extensions/tree/main/extensions/pi-starship",
|
|
212
186
|
],
|
|
@@ -214,16 +188,31 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
214
188
|
}),
|
|
215
189
|
},
|
|
216
190
|
actions: {
|
|
217
|
-
customize: async () =>
|
|
218
|
-
|
|
191
|
+
customize: async () => {
|
|
192
|
+
const result = await editSettings(ctx, options);
|
|
193
|
+
return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
|
|
194
|
+
},
|
|
195
|
+
explain: async () => {
|
|
196
|
+
const result = await showFooterExplanation(ctx, options.getInspection?.(), owner.signal);
|
|
197
|
+
if (!isCurrentOwner(owner)) return { kind: "stay" };
|
|
198
|
+
return result?.kind === "back" ? { kind: "stay" } : { kind: "close" };
|
|
199
|
+
},
|
|
200
|
+
modules: async () => {
|
|
201
|
+
const inspection =
|
|
202
|
+
options.getInspection?.() ?? inspectUnavailableModules(options.getLoaded().config);
|
|
203
|
+
const result = await showModuleBrowser(ctx, inspection, owner.signal);
|
|
204
|
+
if (!isCurrentOwner(owner)) return { kind: "stay" };
|
|
205
|
+
return result?.kind === "back" ? { kind: "stay" } : { kind: "close" };
|
|
206
|
+
},
|
|
219
207
|
restore: async () => {
|
|
220
|
-
|
|
221
|
-
|
|
208
|
+
const presentation = configurationPresentation(options.getLoaded());
|
|
209
|
+
if (presentation.restoreDisabled) {
|
|
210
|
+
ctx.ui.notify(presentation.restoreDescription, "info");
|
|
222
211
|
return { kind: "stay" };
|
|
223
212
|
}
|
|
224
|
-
|
|
213
|
+
const result = await restoreBuiltIn(ctx, options);
|
|
214
|
+
return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
|
|
225
215
|
},
|
|
226
|
-
back: async () => ({ kind: "back" }),
|
|
227
216
|
},
|
|
228
217
|
});
|
|
229
218
|
try {
|
|
@@ -240,17 +229,17 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
240
229
|
async function editSettings(
|
|
241
230
|
ctx: ExtensionCommandContext,
|
|
242
231
|
options: StarshipCommandOptions,
|
|
243
|
-
): Promise<
|
|
232
|
+
): Promise<"applied" | "cancel" | "close"> {
|
|
244
233
|
const owner = workflowOwner(options);
|
|
245
|
-
if (!isCurrentOwner(owner)) return
|
|
234
|
+
if (!isCurrentOwner(owner)) return "cancel";
|
|
246
235
|
if (ctx.mode !== "tui") {
|
|
247
236
|
if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${options.settingsPath}`, "info");
|
|
248
|
-
return
|
|
237
|
+
return "cancel";
|
|
249
238
|
}
|
|
250
239
|
let draft = options.getLoaded().rawDocument ?? BUILT_IN_EXAMPLE;
|
|
251
240
|
while (true) {
|
|
252
241
|
const edited = await ctx.ui.editor("Customize footer — close to preview", draft);
|
|
253
|
-
if (!isCurrentOwner(owner) || edited === undefined) return
|
|
242
|
+
if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
|
|
254
243
|
draft = edited;
|
|
255
244
|
let validated: LoadedStarshipConfig;
|
|
256
245
|
try {
|
|
@@ -263,33 +252,34 @@ async function editSettings(
|
|
|
263
252
|
() => [safeText(formatError(error)), "The current footer has not changed."],
|
|
264
253
|
[
|
|
265
254
|
{ value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
|
|
266
|
-
{ value: PREVIEW_ACTIONS.cancel, label: "
|
|
255
|
+
{ value: PREVIEW_ACTIONS.cancel, label: "Discard draft" },
|
|
267
256
|
],
|
|
257
|
+
owner.signal,
|
|
268
258
|
);
|
|
269
|
-
if (!isCurrentOwner(owner)) return
|
|
270
|
-
if (action ===
|
|
271
|
-
|
|
259
|
+
if (!isCurrentOwner(owner)) return "cancel";
|
|
260
|
+
if (action?.kind === "closed") return "close";
|
|
261
|
+
if (selectedPreviewAction(action) === PREVIEW_ACTIONS.edit) continue;
|
|
262
|
+
return "cancel";
|
|
272
263
|
}
|
|
273
264
|
|
|
274
265
|
const result = await reviewAndApply(ctx, options, validated, "Footer preview", false, owner);
|
|
275
266
|
if (result === "edit") continue;
|
|
276
|
-
return result
|
|
267
|
+
return result;
|
|
277
268
|
}
|
|
278
269
|
}
|
|
279
270
|
|
|
280
271
|
async function restoreBuiltIn(
|
|
281
272
|
ctx: ExtensionCommandContext,
|
|
282
273
|
options: StarshipCommandOptions,
|
|
283
|
-
): Promise<
|
|
274
|
+
): Promise<"applied" | "cancel" | "close"> {
|
|
284
275
|
const owner = workflowOwner(options);
|
|
285
|
-
if (!isCurrentOwner(owner)) return
|
|
276
|
+
if (!isCurrentOwner(owner)) return "cancel";
|
|
286
277
|
const validated = (options.validate ?? validateConfigDocument)(
|
|
287
278
|
options.settingsPath,
|
|
288
279
|
BUILT_IN_EXAMPLE,
|
|
289
280
|
);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
);
|
|
281
|
+
const result = await reviewAndApply(ctx, options, validated, "Restore preview", true, owner);
|
|
282
|
+
return result === "edit" ? "cancel" : result;
|
|
293
283
|
}
|
|
294
284
|
|
|
295
285
|
async function reviewAndApply(
|
|
@@ -299,26 +289,38 @@ async function reviewAndApply(
|
|
|
299
289
|
title: string,
|
|
300
290
|
restore: boolean,
|
|
301
291
|
owner: WorkflowOwner,
|
|
302
|
-
): Promise<"applied" | "edit" | "cancel"> {
|
|
292
|
+
): Promise<"applied" | "edit" | "cancel" | "close"> {
|
|
303
293
|
while (true) {
|
|
304
294
|
const selection = await showPreviewActionMenu(
|
|
305
295
|
ctx,
|
|
306
296
|
title,
|
|
307
|
-
(width) =>
|
|
297
|
+
(width) =>
|
|
298
|
+
restore
|
|
299
|
+
? restorePreviewBody(ctx, options, validated, width)
|
|
300
|
+
: previewBody(ctx, options, validated, width),
|
|
308
301
|
[
|
|
309
|
-
{
|
|
302
|
+
{
|
|
303
|
+
value: PREVIEW_ACTIONS.continue,
|
|
304
|
+
label: restore ? "Replace with built-in…" : "Apply changes…",
|
|
305
|
+
},
|
|
310
306
|
...(restore ? [] : [{ value: PREVIEW_ACTIONS.edit, label: "Continue editing" }]),
|
|
311
|
-
{
|
|
307
|
+
{
|
|
308
|
+
value: PREVIEW_ACTIONS.cancel,
|
|
309
|
+
label: restore ? "Cancel" : "Discard draft",
|
|
310
|
+
},
|
|
312
311
|
],
|
|
312
|
+
owner.signal,
|
|
313
313
|
);
|
|
314
314
|
if (!isCurrentOwner(owner)) return "cancel";
|
|
315
|
-
if (selection ===
|
|
316
|
-
|
|
315
|
+
if (selection?.kind === "closed") return "close";
|
|
316
|
+
const selected = selectedPreviewAction(selection);
|
|
317
|
+
if (selected === PREVIEW_ACTIONS.edit) return "edit";
|
|
318
|
+
if (selected !== PREVIEW_ACTIONS.continue) return "cancel";
|
|
317
319
|
|
|
318
320
|
const confirmed = await ctx.ui.confirm(
|
|
319
321
|
restore ? "Restore built-in footer?" : "Apply footer changes?",
|
|
320
322
|
restore
|
|
321
|
-
? `Replace ${options.settingsPath} with the built-in configuration
|
|
323
|
+
? `Replace ${safeText(options.settingsPath)} entirely with the built-in configuration? All custom settings, unknown fields, and comments will be removed. No backup is kept after success.`
|
|
322
324
|
: "Save this configuration and apply it immediately?",
|
|
323
325
|
);
|
|
324
326
|
if (!isCurrentOwner(owner)) return "cancel";
|
|
@@ -395,6 +397,23 @@ function restorePreviousConfiguration(
|
|
|
395
397
|
}
|
|
396
398
|
}
|
|
397
399
|
|
|
400
|
+
function restorePreviewBody(
|
|
401
|
+
ctx: ExtensionCommandContext,
|
|
402
|
+
options: StarshipCommandOptions,
|
|
403
|
+
loaded: LoadedStarshipConfig,
|
|
404
|
+
width: number,
|
|
405
|
+
): string[] {
|
|
406
|
+
const current = configurationPresentation(options.getLoaded());
|
|
407
|
+
return [
|
|
408
|
+
`Current: ${current.state}`,
|
|
409
|
+
`Path: ${safeText(options.settingsPath)}`,
|
|
410
|
+
"The entire settings document will be replaced, including custom settings, unknown fields, and comments.",
|
|
411
|
+
"No backup is kept after a successful restore.",
|
|
412
|
+
"",
|
|
413
|
+
...previewBody(ctx, options, loaded, width),
|
|
414
|
+
];
|
|
415
|
+
}
|
|
416
|
+
|
|
398
417
|
function previewBody(
|
|
399
418
|
ctx: ExtensionCommandContext,
|
|
400
419
|
options: StarshipCommandOptions,
|
|
@@ -417,46 +436,10 @@ function previewBody(
|
|
|
417
436
|
return [...lines, "", warning];
|
|
418
437
|
}
|
|
419
438
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
items: readonly MenuItem[],
|
|
425
|
-
): Promise<string | null> {
|
|
426
|
-
return ctx.ui.custom<string | null>((tui, theme, _keybindings, done) => {
|
|
427
|
-
const list = new SelectList([...items], Math.min(items.length, 8), {
|
|
428
|
-
selectedPrefix: (text) => theme.fg("accent", text),
|
|
429
|
-
selectedText: (text) => theme.fg("accent", text),
|
|
430
|
-
description: (text) => theme.fg("muted", text),
|
|
431
|
-
scrollInfo: (text) => theme.fg("dim", text),
|
|
432
|
-
noMatch: (text) => theme.fg("warning", text),
|
|
433
|
-
});
|
|
434
|
-
list.onSelect = (item) => done(String(item.value));
|
|
435
|
-
list.onCancel = () => done(null);
|
|
436
|
-
return {
|
|
437
|
-
render(width: number): string[] {
|
|
438
|
-
const safeWidth = Math.max(1, width);
|
|
439
|
-
const content = [
|
|
440
|
-
...wrapTextWithAnsi(theme.fg("accent", theme.bold(title)), safeWidth),
|
|
441
|
-
...body(safeWidth).flatMap((line) => (line ? wrapTextWithAnsi(line, safeWidth) : [""])),
|
|
442
|
-
"",
|
|
443
|
-
...list.render(safeWidth),
|
|
444
|
-
...wrapTextWithAnsi(
|
|
445
|
-
theme.fg("dim", "↑↓ navigate • enter select • esc cancel"),
|
|
446
|
-
safeWidth,
|
|
447
|
-
),
|
|
448
|
-
];
|
|
449
|
-
return content.map((line) => truncateToWidth(line, safeWidth));
|
|
450
|
-
},
|
|
451
|
-
invalidate() {
|
|
452
|
-
list.invalidate();
|
|
453
|
-
},
|
|
454
|
-
handleInput(data: string) {
|
|
455
|
-
list.handleInput(data);
|
|
456
|
-
tui.requestRender();
|
|
457
|
-
},
|
|
458
|
-
};
|
|
459
|
-
});
|
|
439
|
+
function selectedPreviewAction<Value extends string>(
|
|
440
|
+
result: PreviewMenuResult<Value> | undefined,
|
|
441
|
+
): Value | null {
|
|
442
|
+
return result?.kind === "selected" ? result.value : null;
|
|
460
443
|
}
|
|
461
444
|
|
|
462
445
|
function diagnosticLines(loaded: LoadedStarshipConfig, includeSummary: boolean): string[] {
|
|
@@ -471,13 +454,44 @@ function diagnosticLines(loaded: LoadedStarshipConfig, includeSummary: boolean):
|
|
|
471
454
|
];
|
|
472
455
|
}
|
|
473
456
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
457
|
+
interface ConfigurationPresentation {
|
|
458
|
+
state: string;
|
|
459
|
+
source: string;
|
|
460
|
+
health: string;
|
|
461
|
+
restoreDisabled: boolean;
|
|
462
|
+
restoreDescription: string;
|
|
477
463
|
}
|
|
478
464
|
|
|
479
|
-
function
|
|
480
|
-
|
|
465
|
+
function configurationPresentation(loaded: LoadedStarshipConfig): ConfigurationPresentation {
|
|
466
|
+
const healthyMissing =
|
|
467
|
+
loaded.source === "built-in" &&
|
|
468
|
+
loaded.rawDocument === undefined &&
|
|
469
|
+
loaded.diagnostics.length === 0;
|
|
470
|
+
const savedBuiltIn = loaded.source === "user" && loaded.rawDocument === BUILT_IN_EXAMPLE;
|
|
471
|
+
const fallback = loaded.source === "built-in" && loaded.diagnostics.length > 0;
|
|
472
|
+
return {
|
|
473
|
+
state: healthyMissing
|
|
474
|
+
? "Built-in defaults"
|
|
475
|
+
: savedBuiltIn
|
|
476
|
+
? "Saved built-in configuration"
|
|
477
|
+
: fallback
|
|
478
|
+
? "Built-in fallback"
|
|
479
|
+
: "Custom configuration",
|
|
480
|
+
source: healthyMissing
|
|
481
|
+
? "No settings file"
|
|
482
|
+
: loaded.source === "user"
|
|
483
|
+
? "User file"
|
|
484
|
+
: "Built-in fallback",
|
|
485
|
+
health: configurationHealth(loaded),
|
|
486
|
+
restoreDisabled: healthyMissing || savedBuiltIn,
|
|
487
|
+
restoreDescription: healthyMissing
|
|
488
|
+
? "Already using defaults · no file to replace"
|
|
489
|
+
: savedBuiltIn
|
|
490
|
+
? "Built-in configuration already saved"
|
|
491
|
+
: fallback
|
|
492
|
+
? "Preview before replacing invalid settings"
|
|
493
|
+
: "Preview before replacing the document",
|
|
494
|
+
};
|
|
481
495
|
}
|
|
482
496
|
|
|
483
497
|
function configurationHealth(loaded: LoadedStarshipConfig): string {
|
|
@@ -487,10 +501,6 @@ function configurationHealth(loaded: LoadedStarshipConfig): string {
|
|
|
487
501
|
return warnings === 0 ? "Healthy" : `${warnings} warning${warnings === 1 ? "" : "s"}`;
|
|
488
502
|
}
|
|
489
503
|
|
|
490
|
-
function fileName(path: string): string {
|
|
491
|
-
return path.replaceAll("\\", "/").split("/").at(-1) || path;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
504
|
function showStatus(ctx: ExtensionCommandContext, options: StarshipCommandOptions) {
|
|
495
505
|
if (!canNotify(ctx)) return;
|
|
496
506
|
const loaded = options.getLoaded();
|
|
@@ -512,7 +522,7 @@ function showHelp(ctx: ExtensionCommandContext, settingsPath: string) {
|
|
|
512
522
|
if (!canNotify(ctx)) return;
|
|
513
523
|
ctx.ui.notify(
|
|
514
524
|
[
|
|
515
|
-
"/starship —
|
|
525
|
+
"/starship — customize, explain, or inspect the footer in TUI mode",
|
|
516
526
|
"/starship settings — customize, preview, and apply TOML",
|
|
517
527
|
"/starship status — show source, path, and warnings",
|
|
518
528
|
"/starship help — show this help",
|