@narumitw/pi-starship 0.49.4 → 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/NOTICES.md +4 -2
- package/README.md +60 -12
- package/package.json +7 -4
- package/src/command-inspector.ts +19 -176
- package/src/command-preset-picker.ts +203 -0
- package/src/commands.ts +269 -57
- package/src/pi-starship.ts +12 -2
- package/src/presets/bracketed-segments.ts +45 -0
- package/src/presets/catalog.ts +138 -0
- package/src/presets/catppuccin-powerline.ts +90 -0
- package/src/presets/gruvbox-rainbow.ts +66 -0
- package/src/presets/jetpack.ts +51 -0
- package/src/presets/minimal.ts +23 -0
- package/src/presets/nerd-font-symbols.ts +27 -0
- package/src/presets/no-empty-icons.ts +47 -0
- package/src/presets/no-nerd-font.ts +51 -0
- package/src/presets/no-runtime-versions.ts +52 -0
- package/src/presets/pastel-powerline.ts +53 -0
- package/src/presets/plain-text-symbols.ts +52 -0
- package/src/presets/pure-preset.ts +55 -0
- package/src/presets/tokyo-night.ts +53 -0
package/src/commands.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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
|
+
import { showPresetPicker } from "./command-preset-picker.js";
|
|
5
6
|
import { type PreviewMenuResult, showPreviewActionMenu } from "./command-preview.js";
|
|
6
7
|
import {
|
|
7
8
|
atomicRestoreConfigDocument,
|
|
@@ -12,9 +13,16 @@ import {
|
|
|
12
13
|
validateConfigDocument,
|
|
13
14
|
} from "./config.js";
|
|
14
15
|
import { inspectUnavailableModules, type StatuslineInspection } from "./modules/inspection.js";
|
|
16
|
+
import {
|
|
17
|
+
getStarshipPreset,
|
|
18
|
+
presetForDocument,
|
|
19
|
+
STARSHIP_PRESETS,
|
|
20
|
+
type StarshipPreset,
|
|
21
|
+
} from "./presets/catalog.js";
|
|
15
22
|
|
|
16
23
|
const MAIN_ACTIONS = {
|
|
17
24
|
customize: "customize",
|
|
25
|
+
presets: "presets",
|
|
18
26
|
explain: "explain",
|
|
19
27
|
modules: "modules",
|
|
20
28
|
configuration: "configuration",
|
|
@@ -32,6 +40,7 @@ export interface StarshipCommandOptions {
|
|
|
32
40
|
getLoaded(): LoadedStarshipConfig;
|
|
33
41
|
getInspection?(): StatuslineInspection | undefined;
|
|
34
42
|
apply(loaded: LoadedStarshipConfig, ctx: ExtensionCommandContext): void;
|
|
43
|
+
preview?(loaded: LoadedStarshipConfig | undefined, ctx: ExtensionCommandContext): void;
|
|
35
44
|
settingsPath: string;
|
|
36
45
|
renderPreview?(
|
|
37
46
|
loaded: LoadedStarshipConfig,
|
|
@@ -49,6 +58,11 @@ interface WorkflowOwner {
|
|
|
49
58
|
isCurrent(): boolean;
|
|
50
59
|
}
|
|
51
60
|
|
|
61
|
+
type ReviewIntent =
|
|
62
|
+
| { kind: "customize" }
|
|
63
|
+
| { kind: "restore" }
|
|
64
|
+
| { kind: "preset"; preset: StarshipPreset };
|
|
65
|
+
|
|
52
66
|
export function registerStarshipCommand(pi: ExtensionAPI, options: StarshipCommandOptions) {
|
|
53
67
|
pi.registerCommand("starship", {
|
|
54
68
|
description: "Customize or inspect the native Starship-style footer",
|
|
@@ -100,8 +114,8 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
100
114
|
signal: fallbackController.signal,
|
|
101
115
|
isCurrent: () => !fallbackController.signal.aborted,
|
|
102
116
|
};
|
|
103
|
-
type Screen = "main" | "modules" | "configuration" | "help";
|
|
104
|
-
type Action = "customize" | "
|
|
117
|
+
type Screen = "main" | "explain" | "modules" | "configuration" | "help";
|
|
118
|
+
type Action = "customize" | "presets" | "restore";
|
|
105
119
|
const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({
|
|
106
120
|
start: "main",
|
|
107
121
|
screens: {
|
|
@@ -119,11 +133,17 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
119
133
|
description: `${presentation.state} · preview before applying`,
|
|
120
134
|
action: "customize",
|
|
121
135
|
},
|
|
136
|
+
{
|
|
137
|
+
id: MAIN_ACTIONS.presets,
|
|
138
|
+
label: "Presets",
|
|
139
|
+
description: "Browse and live-preview bundled footer starting points",
|
|
140
|
+
action: "presets",
|
|
141
|
+
},
|
|
122
142
|
{
|
|
123
143
|
id: MAIN_ACTIONS.explain,
|
|
124
144
|
label: "Explain footer",
|
|
125
145
|
description: "Why each visible module appears",
|
|
126
|
-
|
|
146
|
+
to: "explain",
|
|
127
147
|
},
|
|
128
148
|
{
|
|
129
149
|
id: MAIN_ACTIONS.modules,
|
|
@@ -154,6 +174,14 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
154
174
|
hint: "close",
|
|
155
175
|
};
|
|
156
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
|
+
}),
|
|
157
185
|
modules: () => {
|
|
158
186
|
const inspection =
|
|
159
187
|
options.getInspection?.() ?? inspectUnavailableModules(options.getLoaded().config);
|
|
@@ -202,11 +230,12 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
202
230
|
title: "pi-starship help",
|
|
203
231
|
lines: [
|
|
204
232
|
"Customize footer opens the TOML editor, then previews and confirms before saving.",
|
|
233
|
+
"Presets live-previews the cursor in the footer; Enter confirms apply and e customizes first.",
|
|
205
234
|
"Explain footer breaks down the modules currently showing from the existing snapshot.",
|
|
206
235
|
"Modules searches every supported module and explains its current read-only state.",
|
|
207
236
|
"Configuration explains state, source, path, and warnings without changing the footer.",
|
|
208
237
|
`Settings: ${safeText(options.settingsPath)}`,
|
|
209
|
-
"Docs: https://github.com/narumiruna/pi-extensions/tree/main/
|
|
238
|
+
"Docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship",
|
|
210
239
|
],
|
|
211
240
|
hint: "back",
|
|
212
241
|
}),
|
|
@@ -216,10 +245,9 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
216
245
|
const result = await editSettings(ctx, options);
|
|
217
246
|
return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
|
|
218
247
|
},
|
|
219
|
-
|
|
220
|
-
const result = await
|
|
221
|
-
|
|
222
|
-
return result?.kind === "back" ? { kind: "stay" } : { kind: "close" };
|
|
248
|
+
presets: async () => {
|
|
249
|
+
const result = await choosePreset(ctx, options, owner);
|
|
250
|
+
return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
|
|
223
251
|
},
|
|
224
252
|
restore: async () => {
|
|
225
253
|
const presentation = configurationPresentation(options.getLoaded());
|
|
@@ -279,12 +307,108 @@ async function editSettings(
|
|
|
279
307
|
return "cancel";
|
|
280
308
|
}
|
|
281
309
|
|
|
282
|
-
const result = await reviewAndApply(ctx, options, validated,
|
|
310
|
+
const result = await reviewAndApply(ctx, options, validated, { kind: "customize" }, owner);
|
|
283
311
|
if (result === "edit") continue;
|
|
284
312
|
return result;
|
|
285
313
|
}
|
|
286
314
|
}
|
|
287
315
|
|
|
316
|
+
async function choosePreset(
|
|
317
|
+
ctx: ExtensionCommandContext,
|
|
318
|
+
options: StarshipCommandOptions,
|
|
319
|
+
owner: WorkflowOwner,
|
|
320
|
+
): Promise<"applied" | "cancel" | "close"> {
|
|
321
|
+
const activePreset = presetForDocument(options.getLoaded().rawDocument);
|
|
322
|
+
const selection = await showPresetPicker(ctx, {
|
|
323
|
+
presets: STARSHIP_PRESETS,
|
|
324
|
+
activePresetId: activePreset?.id,
|
|
325
|
+
initialPresetId: activePreset?.id ?? STARSHIP_PRESETS[0]?.id,
|
|
326
|
+
signal: owner.signal,
|
|
327
|
+
isCurrent: owner.isCurrent,
|
|
328
|
+
preview(preset) {
|
|
329
|
+
const loaded = (options.validate ?? validateConfigDocument)(
|
|
330
|
+
options.settingsPath,
|
|
331
|
+
preset.rawDocument,
|
|
332
|
+
);
|
|
333
|
+
options.preview?.(loaded, ctx);
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
if (!isCurrentOwner(owner)) {
|
|
337
|
+
options.preview?.(undefined, ctx);
|
|
338
|
+
return "cancel";
|
|
339
|
+
}
|
|
340
|
+
if (selection.kind === "back" || selection.kind === "close") {
|
|
341
|
+
options.preview?.(undefined, ctx);
|
|
342
|
+
return selection.kind === "close" ? "close" : "cancel";
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const preset = getStarshipPreset(selection.presetId);
|
|
346
|
+
try {
|
|
347
|
+
return await applyPreset(
|
|
348
|
+
ctx,
|
|
349
|
+
options,
|
|
350
|
+
preset,
|
|
351
|
+
selection.kind === "customize" ? "customize" : "confirm",
|
|
352
|
+
);
|
|
353
|
+
} finally {
|
|
354
|
+
options.preview?.(undefined, ctx);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
async function applyPreset(
|
|
359
|
+
ctx: ExtensionCommandContext,
|
|
360
|
+
options: StarshipCommandOptions,
|
|
361
|
+
preset: StarshipPreset,
|
|
362
|
+
start: "review" | "confirm" | "customize" = "review",
|
|
363
|
+
): Promise<"applied" | "cancel" | "close"> {
|
|
364
|
+
const owner = workflowOwner(options);
|
|
365
|
+
if (!isCurrentOwner(owner)) return "cancel";
|
|
366
|
+
let draft = preset.rawDocument;
|
|
367
|
+
if (start === "customize") {
|
|
368
|
+
const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
|
|
369
|
+
if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
|
|
370
|
+
draft = edited;
|
|
371
|
+
}
|
|
372
|
+
while (true) {
|
|
373
|
+
let validated: LoadedStarshipConfig;
|
|
374
|
+
try {
|
|
375
|
+
validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);
|
|
376
|
+
} catch (error) {
|
|
377
|
+
ctx.ui.notify(`Preset draft is invalid: ${safeText(formatError(error))}`, "error");
|
|
378
|
+
const action = await showPreviewActionMenu(
|
|
379
|
+
ctx,
|
|
380
|
+
"Preset needs attention",
|
|
381
|
+
() => [safeText(formatError(error)), "The current footer has not changed."],
|
|
382
|
+
[
|
|
383
|
+
{ value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
|
|
384
|
+
{ value: PREVIEW_ACTIONS.cancel, label: "Choose another preset" },
|
|
385
|
+
],
|
|
386
|
+
owner.signal,
|
|
387
|
+
);
|
|
388
|
+
if (!isCurrentOwner(owner)) return "cancel";
|
|
389
|
+
if (action?.kind === "closed") return "close";
|
|
390
|
+
if (selectedPreviewAction(action) !== PREVIEW_ACTIONS.edit) return "cancel";
|
|
391
|
+
const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
|
|
392
|
+
if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
|
|
393
|
+
draft = edited;
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const result = await reviewAndApply(
|
|
398
|
+
ctx,
|
|
399
|
+
options,
|
|
400
|
+
validated,
|
|
401
|
+
{ kind: "preset", preset },
|
|
402
|
+
owner,
|
|
403
|
+
start === "confirm",
|
|
404
|
+
);
|
|
405
|
+
if (result !== "edit") return result;
|
|
406
|
+
const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
|
|
407
|
+
if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
|
|
408
|
+
draft = edited;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
288
412
|
async function restoreBuiltIn(
|
|
289
413
|
ctx: ExtensionCommandContext,
|
|
290
414
|
options: StarshipCommandOptions,
|
|
@@ -295,7 +419,7 @@ async function restoreBuiltIn(
|
|
|
295
419
|
options.settingsPath,
|
|
296
420
|
BUILT_IN_EXAMPLE,
|
|
297
421
|
);
|
|
298
|
-
const result = await reviewAndApply(ctx, options, validated,
|
|
422
|
+
const result = await reviewAndApply(ctx, options, validated, { kind: "restore" }, owner);
|
|
299
423
|
return result === "edit" ? "cancel" : result;
|
|
300
424
|
}
|
|
301
425
|
|
|
@@ -303,45 +427,58 @@ async function reviewAndApply(
|
|
|
303
427
|
ctx: ExtensionCommandContext,
|
|
304
428
|
options: StarshipCommandOptions,
|
|
305
429
|
validated: LoadedStarshipConfig,
|
|
306
|
-
|
|
307
|
-
restore: boolean,
|
|
430
|
+
intent: ReviewIntent,
|
|
308
431
|
owner: WorkflowOwner,
|
|
432
|
+
skipReview = false,
|
|
309
433
|
): Promise<"applied" | "edit" | "cancel" | "close"> {
|
|
434
|
+
let reviewRequired = !skipReview;
|
|
310
435
|
while (true) {
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
436
|
+
const directAttempt = !reviewRequired;
|
|
437
|
+
if (reviewRequired) {
|
|
438
|
+
const selection = await showPreviewActionMenu(
|
|
439
|
+
ctx,
|
|
440
|
+
reviewTitle(intent),
|
|
441
|
+
(width) => reviewPreviewBody(ctx, options, validated, width, intent),
|
|
442
|
+
[
|
|
443
|
+
{ value: PREVIEW_ACTIONS.continue, label: continueLabel(intent) },
|
|
444
|
+
...(intent.kind === "restore"
|
|
445
|
+
? []
|
|
446
|
+
: [
|
|
447
|
+
{
|
|
448
|
+
value: PREVIEW_ACTIONS.edit,
|
|
449
|
+
label:
|
|
450
|
+
intent.kind === "preset" ? "Customize before applying" : "Continue editing",
|
|
451
|
+
},
|
|
452
|
+
]),
|
|
453
|
+
{
|
|
454
|
+
value: PREVIEW_ACTIONS.cancel,
|
|
455
|
+
label:
|
|
456
|
+
intent.kind === "restore"
|
|
457
|
+
? "Cancel"
|
|
458
|
+
: intent.kind === "preset"
|
|
459
|
+
? "Choose another preset"
|
|
460
|
+
: "Discard draft",
|
|
461
|
+
},
|
|
462
|
+
],
|
|
463
|
+
owner.signal,
|
|
464
|
+
);
|
|
465
|
+
if (!isCurrentOwner(owner)) return "cancel";
|
|
466
|
+
if (selection?.kind === "closed") return "close";
|
|
467
|
+
const selected = selectedPreviewAction(selection);
|
|
468
|
+
if (selected === PREVIEW_ACTIONS.edit) return "edit";
|
|
469
|
+
if (selected !== PREVIEW_ACTIONS.continue) return "cancel";
|
|
470
|
+
}
|
|
471
|
+
reviewRequired = true;
|
|
336
472
|
|
|
337
473
|
const confirmed = await ctx.ui.confirm(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
? `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.`
|
|
341
|
-
: "Save this configuration and apply it immediately?",
|
|
474
|
+
confirmationTitle(intent),
|
|
475
|
+
confirmationMessage(options.settingsPath, intent),
|
|
342
476
|
);
|
|
343
477
|
if (!isCurrentOwner(owner)) return "cancel";
|
|
344
|
-
if (!confirmed)
|
|
478
|
+
if (!confirmed) {
|
|
479
|
+
if (directAttempt) return "cancel";
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
345
482
|
|
|
346
483
|
const save = options.save ?? atomicSaveConfigDocument;
|
|
347
484
|
const previous = options.getLoaded();
|
|
@@ -353,6 +490,7 @@ async function reviewAndApply(
|
|
|
353
490
|
`Footer settings were not saved: ${safeText(formatError(error))}. The previous footer remains active.`,
|
|
354
491
|
"error",
|
|
355
492
|
);
|
|
493
|
+
if (directAttempt) return "cancel";
|
|
356
494
|
continue;
|
|
357
495
|
}
|
|
358
496
|
|
|
@@ -366,6 +504,7 @@ async function reviewAndApply(
|
|
|
366
504
|
: `Footer settings could not be applied: ${safeText(formatError(error))}. The previous configuration was restored.`,
|
|
367
505
|
"error",
|
|
368
506
|
);
|
|
507
|
+
if (directAttempt) return "cancel";
|
|
369
508
|
continue;
|
|
370
509
|
}
|
|
371
510
|
|
|
@@ -373,16 +512,62 @@ async function reviewAndApply(
|
|
|
373
512
|
saved.diagnostics.length > 0
|
|
374
513
|
? ` (${saved.diagnostics.length} warning${saved.diagnostics.length === 1 ? "" : "s"})`
|
|
375
514
|
: "";
|
|
376
|
-
ctx.ui.notify(
|
|
377
|
-
restore
|
|
378
|
-
? `Built-in footer restored and applied${warningSuffix}.`
|
|
379
|
-
: `Footer settings saved and applied${warningSuffix}.`,
|
|
380
|
-
"info",
|
|
381
|
-
);
|
|
515
|
+
ctx.ui.notify(`${successMessage(intent)}${warningSuffix}.`, "info");
|
|
382
516
|
return "applied";
|
|
383
517
|
}
|
|
384
518
|
}
|
|
385
519
|
|
|
520
|
+
function reviewTitle(intent: ReviewIntent): string {
|
|
521
|
+
switch (intent.kind) {
|
|
522
|
+
case "customize":
|
|
523
|
+
return "Footer preview";
|
|
524
|
+
case "restore":
|
|
525
|
+
return "Restore preview";
|
|
526
|
+
case "preset":
|
|
527
|
+
return `${intent.preset.label} preset preview`;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function continueLabel(intent: ReviewIntent): string {
|
|
532
|
+
switch (intent.kind) {
|
|
533
|
+
case "customize":
|
|
534
|
+
return "Apply changes…";
|
|
535
|
+
case "restore":
|
|
536
|
+
return "Replace with built-in…";
|
|
537
|
+
case "preset":
|
|
538
|
+
return `Apply ${intent.preset.label} preset…`;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function confirmationTitle(intent: ReviewIntent): string {
|
|
543
|
+
switch (intent.kind) {
|
|
544
|
+
case "customize":
|
|
545
|
+
return "Apply footer changes?";
|
|
546
|
+
case "restore":
|
|
547
|
+
return "Restore built-in footer?";
|
|
548
|
+
case "preset":
|
|
549
|
+
return `Apply ${intent.preset.label} preset?`;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function confirmationMessage(settingsPath: string, intent: ReviewIntent): string {
|
|
554
|
+
if (intent.kind === "customize") return "Save this configuration and apply it immediately?";
|
|
555
|
+
const replacement =
|
|
556
|
+
intent.kind === "restore" ? "the built-in configuration" : `the ${intent.preset.label} preset`;
|
|
557
|
+
return `Replace ${safeText(settingsPath)} entirely with ${replacement}? All custom settings, unknown fields, and comments will be removed. No backup is kept after success.`;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function successMessage(intent: ReviewIntent): string {
|
|
561
|
+
switch (intent.kind) {
|
|
562
|
+
case "customize":
|
|
563
|
+
return "Footer settings saved and applied";
|
|
564
|
+
case "restore":
|
|
565
|
+
return "Built-in footer restored and applied";
|
|
566
|
+
case "preset":
|
|
567
|
+
return `${intent.preset.label} preset saved and applied`;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
386
571
|
function modulePreviewDetails(preview: string): string[] {
|
|
387
572
|
const lines = preview ? preview.split("\n") : ["(no current preview)"];
|
|
388
573
|
return lines.map((line, index) => `${index === 0 ? "Preview: " : " "}${line}`);
|
|
@@ -419,6 +604,28 @@ function restorePreviousConfiguration(
|
|
|
419
604
|
}
|
|
420
605
|
}
|
|
421
606
|
|
|
607
|
+
function reviewPreviewBody(
|
|
608
|
+
ctx: ExtensionCommandContext,
|
|
609
|
+
options: StarshipCommandOptions,
|
|
610
|
+
loaded: LoadedStarshipConfig,
|
|
611
|
+
width: number,
|
|
612
|
+
intent: ReviewIntent,
|
|
613
|
+
): string[] {
|
|
614
|
+
if (intent.kind === "restore") return restorePreviewBody(ctx, options, loaded, width);
|
|
615
|
+
if (intent.kind === "customize") return previewBody(ctx, options, loaded, width);
|
|
616
|
+
const current = configurationPresentation(options.getLoaded());
|
|
617
|
+
return [
|
|
618
|
+
`Preset: ${intent.preset.label}`,
|
|
619
|
+
`Requirement: ${intent.preset.requiresNerdFont ? "Nerd Font" : "No special font"}`,
|
|
620
|
+
`Current: ${current.state}`,
|
|
621
|
+
`Path: ${safeText(options.settingsPath)}`,
|
|
622
|
+
"Applying replaces the entire settings document, including custom settings, unknown fields, and comments.",
|
|
623
|
+
"No backup is kept after a successful apply.",
|
|
624
|
+
"",
|
|
625
|
+
...previewBody(ctx, options, loaded, width),
|
|
626
|
+
];
|
|
627
|
+
}
|
|
628
|
+
|
|
422
629
|
function restorePreviewBody(
|
|
423
630
|
ctx: ExtensionCommandContext,
|
|
424
631
|
options: StarshipCommandOptions,
|
|
@@ -490,20 +697,25 @@ function configurationPresentation(loaded: LoadedStarshipConfig): ConfigurationP
|
|
|
490
697
|
loaded.rawDocument === undefined &&
|
|
491
698
|
loaded.diagnostics.length === 0;
|
|
492
699
|
const savedBuiltIn = loaded.source === "user" && loaded.rawDocument === BUILT_IN_EXAMPLE;
|
|
700
|
+
const activePreset = presetForDocument(loaded.rawDocument);
|
|
493
701
|
const fallback = loaded.source === "built-in" && loaded.diagnostics.length > 0;
|
|
494
702
|
return {
|
|
495
703
|
state: healthyMissing
|
|
496
704
|
? "Built-in defaults"
|
|
497
705
|
: savedBuiltIn
|
|
498
706
|
? "Saved built-in configuration"
|
|
499
|
-
:
|
|
500
|
-
?
|
|
501
|
-
:
|
|
707
|
+
: activePreset
|
|
708
|
+
? `${activePreset.label} preset`
|
|
709
|
+
: fallback
|
|
710
|
+
? "Built-in fallback"
|
|
711
|
+
: "Custom configuration",
|
|
502
712
|
source: healthyMissing
|
|
503
713
|
? "No settings file"
|
|
504
|
-
:
|
|
505
|
-
? "
|
|
506
|
-
:
|
|
714
|
+
: activePreset
|
|
715
|
+
? "Bundled preset"
|
|
716
|
+
: loaded.source === "user"
|
|
717
|
+
? "User file"
|
|
718
|
+
: "Built-in fallback",
|
|
507
719
|
health: configurationHealth(loaded),
|
|
508
720
|
restoreDisabled: healthyMissing || savedBuiltIn,
|
|
509
721
|
restoreDescription: healthyMissing
|
|
@@ -544,12 +756,12 @@ function showHelp(ctx: ExtensionCommandContext, settingsPath: string) {
|
|
|
544
756
|
if (!canNotify(ctx)) return;
|
|
545
757
|
ctx.ui.notify(
|
|
546
758
|
[
|
|
547
|
-
"/starship — customize, explain, or inspect the footer in TUI mode",
|
|
759
|
+
"/starship — customize, live-preview presets, explain, or inspect the footer in TUI mode",
|
|
548
760
|
"/starship settings — customize, preview, and apply TOML",
|
|
549
761
|
"/starship status — show source, path, and warnings",
|
|
550
762
|
"/starship help — show this help",
|
|
551
763
|
`Settings: ${settingsPath}`,
|
|
552
|
-
"Format/module docs: https://github.com/narumiruna/pi-extensions/tree/main/
|
|
764
|
+
"Format/module docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship",
|
|
553
765
|
].join("\n"),
|
|
554
766
|
"info",
|
|
555
767
|
);
|
package/src/pi-starship.ts
CHANGED
|
@@ -85,6 +85,7 @@ interface PiStarshipOptions {
|
|
|
85
85
|
|
|
86
86
|
export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions = {}) {
|
|
87
87
|
let loaded: LoadedStarshipConfig | undefined;
|
|
88
|
+
let previewLoaded: LoadedStarshipConfig | undefined;
|
|
88
89
|
const runtime: RuntimeState = {
|
|
89
90
|
activeTools: new Map(),
|
|
90
91
|
isStreaming: false,
|
|
@@ -252,6 +253,7 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
252
253
|
const installFooter = (ctx: ExtensionContext) => {
|
|
253
254
|
const generation = ++sessionGeneration;
|
|
254
255
|
sessionOwner = ctx.sessionManager;
|
|
256
|
+
previewLoaded = undefined;
|
|
255
257
|
menuController.abort(new DOMException("Starship session context replaced", "AbortError"));
|
|
256
258
|
menuController = new AbortController();
|
|
257
259
|
const target: RefreshTarget = { cwd: ctx.cwd, generation, sessionManager: ctx.sessionManager };
|
|
@@ -328,10 +330,11 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
328
330
|
invalidate() {},
|
|
329
331
|
render(width: number): string[] {
|
|
330
332
|
runtime.footerWidth = width;
|
|
331
|
-
|
|
333
|
+
const current = previewLoaded ?? loaded;
|
|
334
|
+
if (!current) return [];
|
|
332
335
|
const snapshot = runtimeSnapshot(ctx, footerData, runtime);
|
|
333
336
|
return wrapFormattedStatusline(
|
|
334
|
-
renderStatusline(
|
|
337
|
+
renderStatusline(current.config, snapshot, width).ansi,
|
|
335
338
|
width,
|
|
336
339
|
);
|
|
337
340
|
},
|
|
@@ -360,6 +363,7 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
360
363
|
if (sessionOwner !== ctx.sessionManager) {
|
|
361
364
|
throw new Error("Starship session context was replaced");
|
|
362
365
|
}
|
|
366
|
+
previewLoaded = undefined;
|
|
363
367
|
loaded = next;
|
|
364
368
|
const target = activeTarget;
|
|
365
369
|
if (target) {
|
|
@@ -370,6 +374,11 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
370
374
|
}
|
|
371
375
|
refresh();
|
|
372
376
|
},
|
|
377
|
+
preview(next, ctx) {
|
|
378
|
+
if (sessionOwner !== ctx.sessionManager) return;
|
|
379
|
+
previewLoaded = next;
|
|
380
|
+
refresh();
|
|
381
|
+
},
|
|
373
382
|
renderPreview(preview, width) {
|
|
374
383
|
return (
|
|
375
384
|
runtime.renderPreview?.(preview, width) ?? [
|
|
@@ -405,6 +414,7 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
405
414
|
pi.on("session_shutdown", (_event, ctx) => {
|
|
406
415
|
if (sessionOwner !== ctx.sessionManager) return;
|
|
407
416
|
sessionOwner = undefined;
|
|
417
|
+
previewLoaded = undefined;
|
|
408
418
|
sessionGeneration += 1;
|
|
409
419
|
menuController.abort(new DOMException("Starship session shut down", "AbortError"));
|
|
410
420
|
activeTarget = undefined;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const BRACKETED_SEGMENTS_PRESET = String.raw`# Font-safe bracketed segments inspired by Starship.
|
|
2
|
+
format = "$brand$model$thinking$directory$git_branch$git_status$activity$context$time"
|
|
3
|
+
|
|
4
|
+
[brand]
|
|
5
|
+
format = '[\[$symbol\]]($style) '
|
|
6
|
+
style = "bold white"
|
|
7
|
+
|
|
8
|
+
[model]
|
|
9
|
+
format = '[\[$symbol $model\]]($style) '
|
|
10
|
+
symbol = "AI"
|
|
11
|
+
style = "bold blue"
|
|
12
|
+
|
|
13
|
+
[thinking]
|
|
14
|
+
format = '[\[$symbol $level\]]($style) '
|
|
15
|
+
symbol = "think"
|
|
16
|
+
style = "bold purple"
|
|
17
|
+
|
|
18
|
+
[directory]
|
|
19
|
+
format = '[\[$symbol $path\]]($style) '
|
|
20
|
+
symbol = "dir"
|
|
21
|
+
style = "cyan bold"
|
|
22
|
+
|
|
23
|
+
[git_branch]
|
|
24
|
+
format = '[\[$symbol $branch\]]($style) '
|
|
25
|
+
symbol = "git"
|
|
26
|
+
style = "bold purple"
|
|
27
|
+
|
|
28
|
+
[git_status]
|
|
29
|
+
format = '[\[$all_status( $ahead_behind)\]]($style) '
|
|
30
|
+
style = "red bold"
|
|
31
|
+
|
|
32
|
+
[activity]
|
|
33
|
+
format = '[\[$text\]]($style) '
|
|
34
|
+
symbol = "run"
|
|
35
|
+
style = "bold yellow"
|
|
36
|
+
|
|
37
|
+
[context]
|
|
38
|
+
format = '[\[$symbol $percentage\]]($style) '
|
|
39
|
+
symbol = "ctx"
|
|
40
|
+
|
|
41
|
+
[time]
|
|
42
|
+
format = '[\[$time\]]($style)'
|
|
43
|
+
symbol = ""
|
|
44
|
+
style = "bold yellow"
|
|
45
|
+
`;
|