@narumitw/pi-starship 0.49.4 → 0.50.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/NOTICES.md +4 -2
- package/README.md +60 -12
- package/package.json +7 -4
- package/src/command-preset-picker.ts +203 -0
- package/src/commands.ts +259 -50
- 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
|
@@ -2,6 +2,7 @@ import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-c
|
|
|
2
2
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
3
3
|
import { completeStarshipArguments, STARSHIP_SUBCOMMANDS } from "./command-contract.js";
|
|
4
4
|
import { showFooterExplanation } 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",
|
|
@@ -101,7 +115,7 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
101
115
|
isCurrent: () => !fallbackController.signal.aborted,
|
|
102
116
|
};
|
|
103
117
|
type Screen = "main" | "modules" | "configuration" | "help";
|
|
104
|
-
type Action = "customize" | "explain" | "restore";
|
|
118
|
+
type Action = "customize" | "presets" | "explain" | "restore";
|
|
105
119
|
const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({
|
|
106
120
|
start: "main",
|
|
107
121
|
screens: {
|
|
@@ -119,6 +133,12 @@ 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",
|
|
@@ -202,11 +222,12 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
202
222
|
title: "pi-starship help",
|
|
203
223
|
lines: [
|
|
204
224
|
"Customize footer opens the TOML editor, then previews and confirms before saving.",
|
|
225
|
+
"Presets live-previews the cursor in the footer; Enter confirms apply and e customizes first.",
|
|
205
226
|
"Explain footer breaks down the modules currently showing from the existing snapshot.",
|
|
206
227
|
"Modules searches every supported module and explains its current read-only state.",
|
|
207
228
|
"Configuration explains state, source, path, and warnings without changing the footer.",
|
|
208
229
|
`Settings: ${safeText(options.settingsPath)}`,
|
|
209
|
-
"Docs: https://github.com/narumiruna/pi-extensions/tree/main/
|
|
230
|
+
"Docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship",
|
|
210
231
|
],
|
|
211
232
|
hint: "back",
|
|
212
233
|
}),
|
|
@@ -221,6 +242,10 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
221
242
|
if (!isCurrentOwner(owner)) return { kind: "stay" };
|
|
222
243
|
return result?.kind === "back" ? { kind: "stay" } : { kind: "close" };
|
|
223
244
|
},
|
|
245
|
+
presets: async () => {
|
|
246
|
+
const result = await choosePreset(ctx, options, owner);
|
|
247
|
+
return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
|
|
248
|
+
},
|
|
224
249
|
restore: async () => {
|
|
225
250
|
const presentation = configurationPresentation(options.getLoaded());
|
|
226
251
|
if (presentation.restoreDisabled) {
|
|
@@ -279,12 +304,108 @@ async function editSettings(
|
|
|
279
304
|
return "cancel";
|
|
280
305
|
}
|
|
281
306
|
|
|
282
|
-
const result = await reviewAndApply(ctx, options, validated,
|
|
307
|
+
const result = await reviewAndApply(ctx, options, validated, { kind: "customize" }, owner);
|
|
283
308
|
if (result === "edit") continue;
|
|
284
309
|
return result;
|
|
285
310
|
}
|
|
286
311
|
}
|
|
287
312
|
|
|
313
|
+
async function choosePreset(
|
|
314
|
+
ctx: ExtensionCommandContext,
|
|
315
|
+
options: StarshipCommandOptions,
|
|
316
|
+
owner: WorkflowOwner,
|
|
317
|
+
): Promise<"applied" | "cancel" | "close"> {
|
|
318
|
+
const activePreset = presetForDocument(options.getLoaded().rawDocument);
|
|
319
|
+
const selection = await showPresetPicker(ctx, {
|
|
320
|
+
presets: STARSHIP_PRESETS,
|
|
321
|
+
activePresetId: activePreset?.id,
|
|
322
|
+
initialPresetId: activePreset?.id ?? STARSHIP_PRESETS[0]?.id,
|
|
323
|
+
signal: owner.signal,
|
|
324
|
+
isCurrent: owner.isCurrent,
|
|
325
|
+
preview(preset) {
|
|
326
|
+
const loaded = (options.validate ?? validateConfigDocument)(
|
|
327
|
+
options.settingsPath,
|
|
328
|
+
preset.rawDocument,
|
|
329
|
+
);
|
|
330
|
+
options.preview?.(loaded, ctx);
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
if (!isCurrentOwner(owner)) {
|
|
334
|
+
options.preview?.(undefined, ctx);
|
|
335
|
+
return "cancel";
|
|
336
|
+
}
|
|
337
|
+
if (selection.kind === "back" || selection.kind === "close") {
|
|
338
|
+
options.preview?.(undefined, ctx);
|
|
339
|
+
return selection.kind === "close" ? "close" : "cancel";
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const preset = getStarshipPreset(selection.presetId);
|
|
343
|
+
try {
|
|
344
|
+
return await applyPreset(
|
|
345
|
+
ctx,
|
|
346
|
+
options,
|
|
347
|
+
preset,
|
|
348
|
+
selection.kind === "customize" ? "customize" : "confirm",
|
|
349
|
+
);
|
|
350
|
+
} finally {
|
|
351
|
+
options.preview?.(undefined, ctx);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
async function applyPreset(
|
|
356
|
+
ctx: ExtensionCommandContext,
|
|
357
|
+
options: StarshipCommandOptions,
|
|
358
|
+
preset: StarshipPreset,
|
|
359
|
+
start: "review" | "confirm" | "customize" = "review",
|
|
360
|
+
): Promise<"applied" | "cancel" | "close"> {
|
|
361
|
+
const owner = workflowOwner(options);
|
|
362
|
+
if (!isCurrentOwner(owner)) return "cancel";
|
|
363
|
+
let draft = preset.rawDocument;
|
|
364
|
+
if (start === "customize") {
|
|
365
|
+
const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
|
|
366
|
+
if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
|
|
367
|
+
draft = edited;
|
|
368
|
+
}
|
|
369
|
+
while (true) {
|
|
370
|
+
let validated: LoadedStarshipConfig;
|
|
371
|
+
try {
|
|
372
|
+
validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);
|
|
373
|
+
} catch (error) {
|
|
374
|
+
ctx.ui.notify(`Preset draft is invalid: ${safeText(formatError(error))}`, "error");
|
|
375
|
+
const action = await showPreviewActionMenu(
|
|
376
|
+
ctx,
|
|
377
|
+
"Preset needs attention",
|
|
378
|
+
() => [safeText(formatError(error)), "The current footer has not changed."],
|
|
379
|
+
[
|
|
380
|
+
{ value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
|
|
381
|
+
{ value: PREVIEW_ACTIONS.cancel, label: "Choose another preset" },
|
|
382
|
+
],
|
|
383
|
+
owner.signal,
|
|
384
|
+
);
|
|
385
|
+
if (!isCurrentOwner(owner)) return "cancel";
|
|
386
|
+
if (action?.kind === "closed") return "close";
|
|
387
|
+
if (selectedPreviewAction(action) !== PREVIEW_ACTIONS.edit) return "cancel";
|
|
388
|
+
const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
|
|
389
|
+
if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
|
|
390
|
+
draft = edited;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const result = await reviewAndApply(
|
|
395
|
+
ctx,
|
|
396
|
+
options,
|
|
397
|
+
validated,
|
|
398
|
+
{ kind: "preset", preset },
|
|
399
|
+
owner,
|
|
400
|
+
start === "confirm",
|
|
401
|
+
);
|
|
402
|
+
if (result !== "edit") return result;
|
|
403
|
+
const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
|
|
404
|
+
if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
|
|
405
|
+
draft = edited;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
288
409
|
async function restoreBuiltIn(
|
|
289
410
|
ctx: ExtensionCommandContext,
|
|
290
411
|
options: StarshipCommandOptions,
|
|
@@ -295,7 +416,7 @@ async function restoreBuiltIn(
|
|
|
295
416
|
options.settingsPath,
|
|
296
417
|
BUILT_IN_EXAMPLE,
|
|
297
418
|
);
|
|
298
|
-
const result = await reviewAndApply(ctx, options, validated,
|
|
419
|
+
const result = await reviewAndApply(ctx, options, validated, { kind: "restore" }, owner);
|
|
299
420
|
return result === "edit" ? "cancel" : result;
|
|
300
421
|
}
|
|
301
422
|
|
|
@@ -303,45 +424,58 @@ async function reviewAndApply(
|
|
|
303
424
|
ctx: ExtensionCommandContext,
|
|
304
425
|
options: StarshipCommandOptions,
|
|
305
426
|
validated: LoadedStarshipConfig,
|
|
306
|
-
|
|
307
|
-
restore: boolean,
|
|
427
|
+
intent: ReviewIntent,
|
|
308
428
|
owner: WorkflowOwner,
|
|
429
|
+
skipReview = false,
|
|
309
430
|
): Promise<"applied" | "edit" | "cancel" | "close"> {
|
|
431
|
+
let reviewRequired = !skipReview;
|
|
310
432
|
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
|
-
|
|
433
|
+
const directAttempt = !reviewRequired;
|
|
434
|
+
if (reviewRequired) {
|
|
435
|
+
const selection = await showPreviewActionMenu(
|
|
436
|
+
ctx,
|
|
437
|
+
reviewTitle(intent),
|
|
438
|
+
(width) => reviewPreviewBody(ctx, options, validated, width, intent),
|
|
439
|
+
[
|
|
440
|
+
{ value: PREVIEW_ACTIONS.continue, label: continueLabel(intent) },
|
|
441
|
+
...(intent.kind === "restore"
|
|
442
|
+
? []
|
|
443
|
+
: [
|
|
444
|
+
{
|
|
445
|
+
value: PREVIEW_ACTIONS.edit,
|
|
446
|
+
label:
|
|
447
|
+
intent.kind === "preset" ? "Customize before applying" : "Continue editing",
|
|
448
|
+
},
|
|
449
|
+
]),
|
|
450
|
+
{
|
|
451
|
+
value: PREVIEW_ACTIONS.cancel,
|
|
452
|
+
label:
|
|
453
|
+
intent.kind === "restore"
|
|
454
|
+
? "Cancel"
|
|
455
|
+
: intent.kind === "preset"
|
|
456
|
+
? "Choose another preset"
|
|
457
|
+
: "Discard draft",
|
|
458
|
+
},
|
|
459
|
+
],
|
|
460
|
+
owner.signal,
|
|
461
|
+
);
|
|
462
|
+
if (!isCurrentOwner(owner)) return "cancel";
|
|
463
|
+
if (selection?.kind === "closed") return "close";
|
|
464
|
+
const selected = selectedPreviewAction(selection);
|
|
465
|
+
if (selected === PREVIEW_ACTIONS.edit) return "edit";
|
|
466
|
+
if (selected !== PREVIEW_ACTIONS.continue) return "cancel";
|
|
467
|
+
}
|
|
468
|
+
reviewRequired = true;
|
|
336
469
|
|
|
337
470
|
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?",
|
|
471
|
+
confirmationTitle(intent),
|
|
472
|
+
confirmationMessage(options.settingsPath, intent),
|
|
342
473
|
);
|
|
343
474
|
if (!isCurrentOwner(owner)) return "cancel";
|
|
344
|
-
if (!confirmed)
|
|
475
|
+
if (!confirmed) {
|
|
476
|
+
if (directAttempt) return "cancel";
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
345
479
|
|
|
346
480
|
const save = options.save ?? atomicSaveConfigDocument;
|
|
347
481
|
const previous = options.getLoaded();
|
|
@@ -353,6 +487,7 @@ async function reviewAndApply(
|
|
|
353
487
|
`Footer settings were not saved: ${safeText(formatError(error))}. The previous footer remains active.`,
|
|
354
488
|
"error",
|
|
355
489
|
);
|
|
490
|
+
if (directAttempt) return "cancel";
|
|
356
491
|
continue;
|
|
357
492
|
}
|
|
358
493
|
|
|
@@ -366,6 +501,7 @@ async function reviewAndApply(
|
|
|
366
501
|
: `Footer settings could not be applied: ${safeText(formatError(error))}. The previous configuration was restored.`,
|
|
367
502
|
"error",
|
|
368
503
|
);
|
|
504
|
+
if (directAttempt) return "cancel";
|
|
369
505
|
continue;
|
|
370
506
|
}
|
|
371
507
|
|
|
@@ -373,16 +509,62 @@ async function reviewAndApply(
|
|
|
373
509
|
saved.diagnostics.length > 0
|
|
374
510
|
? ` (${saved.diagnostics.length} warning${saved.diagnostics.length === 1 ? "" : "s"})`
|
|
375
511
|
: "";
|
|
376
|
-
ctx.ui.notify(
|
|
377
|
-
restore
|
|
378
|
-
? `Built-in footer restored and applied${warningSuffix}.`
|
|
379
|
-
: `Footer settings saved and applied${warningSuffix}.`,
|
|
380
|
-
"info",
|
|
381
|
-
);
|
|
512
|
+
ctx.ui.notify(`${successMessage(intent)}${warningSuffix}.`, "info");
|
|
382
513
|
return "applied";
|
|
383
514
|
}
|
|
384
515
|
}
|
|
385
516
|
|
|
517
|
+
function reviewTitle(intent: ReviewIntent): string {
|
|
518
|
+
switch (intent.kind) {
|
|
519
|
+
case "customize":
|
|
520
|
+
return "Footer preview";
|
|
521
|
+
case "restore":
|
|
522
|
+
return "Restore preview";
|
|
523
|
+
case "preset":
|
|
524
|
+
return `${intent.preset.label} preset preview`;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function continueLabel(intent: ReviewIntent): string {
|
|
529
|
+
switch (intent.kind) {
|
|
530
|
+
case "customize":
|
|
531
|
+
return "Apply changes…";
|
|
532
|
+
case "restore":
|
|
533
|
+
return "Replace with built-in…";
|
|
534
|
+
case "preset":
|
|
535
|
+
return `Apply ${intent.preset.label} preset…`;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function confirmationTitle(intent: ReviewIntent): string {
|
|
540
|
+
switch (intent.kind) {
|
|
541
|
+
case "customize":
|
|
542
|
+
return "Apply footer changes?";
|
|
543
|
+
case "restore":
|
|
544
|
+
return "Restore built-in footer?";
|
|
545
|
+
case "preset":
|
|
546
|
+
return `Apply ${intent.preset.label} preset?`;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function confirmationMessage(settingsPath: string, intent: ReviewIntent): string {
|
|
551
|
+
if (intent.kind === "customize") return "Save this configuration and apply it immediately?";
|
|
552
|
+
const replacement =
|
|
553
|
+
intent.kind === "restore" ? "the built-in configuration" : `the ${intent.preset.label} preset`;
|
|
554
|
+
return `Replace ${safeText(settingsPath)} entirely with ${replacement}? All custom settings, unknown fields, and comments will be removed. No backup is kept after success.`;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function successMessage(intent: ReviewIntent): string {
|
|
558
|
+
switch (intent.kind) {
|
|
559
|
+
case "customize":
|
|
560
|
+
return "Footer settings saved and applied";
|
|
561
|
+
case "restore":
|
|
562
|
+
return "Built-in footer restored and applied";
|
|
563
|
+
case "preset":
|
|
564
|
+
return `${intent.preset.label} preset saved and applied`;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
386
568
|
function modulePreviewDetails(preview: string): string[] {
|
|
387
569
|
const lines = preview ? preview.split("\n") : ["(no current preview)"];
|
|
388
570
|
return lines.map((line, index) => `${index === 0 ? "Preview: " : " "}${line}`);
|
|
@@ -419,6 +601,28 @@ function restorePreviousConfiguration(
|
|
|
419
601
|
}
|
|
420
602
|
}
|
|
421
603
|
|
|
604
|
+
function reviewPreviewBody(
|
|
605
|
+
ctx: ExtensionCommandContext,
|
|
606
|
+
options: StarshipCommandOptions,
|
|
607
|
+
loaded: LoadedStarshipConfig,
|
|
608
|
+
width: number,
|
|
609
|
+
intent: ReviewIntent,
|
|
610
|
+
): string[] {
|
|
611
|
+
if (intent.kind === "restore") return restorePreviewBody(ctx, options, loaded, width);
|
|
612
|
+
if (intent.kind === "customize") return previewBody(ctx, options, loaded, width);
|
|
613
|
+
const current = configurationPresentation(options.getLoaded());
|
|
614
|
+
return [
|
|
615
|
+
`Preset: ${intent.preset.label}`,
|
|
616
|
+
`Requirement: ${intent.preset.requiresNerdFont ? "Nerd Font" : "No special font"}`,
|
|
617
|
+
`Current: ${current.state}`,
|
|
618
|
+
`Path: ${safeText(options.settingsPath)}`,
|
|
619
|
+
"Applying replaces the entire settings document, including custom settings, unknown fields, and comments.",
|
|
620
|
+
"No backup is kept after a successful apply.",
|
|
621
|
+
"",
|
|
622
|
+
...previewBody(ctx, options, loaded, width),
|
|
623
|
+
];
|
|
624
|
+
}
|
|
625
|
+
|
|
422
626
|
function restorePreviewBody(
|
|
423
627
|
ctx: ExtensionCommandContext,
|
|
424
628
|
options: StarshipCommandOptions,
|
|
@@ -490,20 +694,25 @@ function configurationPresentation(loaded: LoadedStarshipConfig): ConfigurationP
|
|
|
490
694
|
loaded.rawDocument === undefined &&
|
|
491
695
|
loaded.diagnostics.length === 0;
|
|
492
696
|
const savedBuiltIn = loaded.source === "user" && loaded.rawDocument === BUILT_IN_EXAMPLE;
|
|
697
|
+
const activePreset = presetForDocument(loaded.rawDocument);
|
|
493
698
|
const fallback = loaded.source === "built-in" && loaded.diagnostics.length > 0;
|
|
494
699
|
return {
|
|
495
700
|
state: healthyMissing
|
|
496
701
|
? "Built-in defaults"
|
|
497
702
|
: savedBuiltIn
|
|
498
703
|
? "Saved built-in configuration"
|
|
499
|
-
:
|
|
500
|
-
?
|
|
501
|
-
:
|
|
704
|
+
: activePreset
|
|
705
|
+
? `${activePreset.label} preset`
|
|
706
|
+
: fallback
|
|
707
|
+
? "Built-in fallback"
|
|
708
|
+
: "Custom configuration",
|
|
502
709
|
source: healthyMissing
|
|
503
710
|
? "No settings file"
|
|
504
|
-
:
|
|
505
|
-
? "
|
|
506
|
-
:
|
|
711
|
+
: activePreset
|
|
712
|
+
? "Bundled preset"
|
|
713
|
+
: loaded.source === "user"
|
|
714
|
+
? "User file"
|
|
715
|
+
: "Built-in fallback",
|
|
507
716
|
health: configurationHealth(loaded),
|
|
508
717
|
restoreDisabled: healthyMissing || savedBuiltIn,
|
|
509
718
|
restoreDescription: healthyMissing
|
|
@@ -544,12 +753,12 @@ function showHelp(ctx: ExtensionCommandContext, settingsPath: string) {
|
|
|
544
753
|
if (!canNotify(ctx)) return;
|
|
545
754
|
ctx.ui.notify(
|
|
546
755
|
[
|
|
547
|
-
"/starship — customize, explain, or inspect the footer in TUI mode",
|
|
756
|
+
"/starship — customize, live-preview presets, explain, or inspect the footer in TUI mode",
|
|
548
757
|
"/starship settings — customize, preview, and apply TOML",
|
|
549
758
|
"/starship status — show source, path, and warnings",
|
|
550
759
|
"/starship help — show this help",
|
|
551
760
|
`Settings: ${settingsPath}`,
|
|
552
|
-
"Format/module docs: https://github.com/narumiruna/pi-extensions/tree/main/
|
|
761
|
+
"Format/module docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship",
|
|
553
762
|
].join("\n"),
|
|
554
763
|
"info",
|
|
555
764
|
);
|
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
|
+
`;
|