@narumitw/pi-starship 0.49.3 → 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 +62 -16
- package/package.json +10 -11
- package/src/command-contract.ts +13 -0
- package/src/command-inspector.ts +198 -0
- package/src/command-preset-picker.ts +203 -0
- package/src/command-preview.ts +206 -0
- package/src/commands.ts +784 -0
- package/src/config.ts +794 -0
- package/src/format/formatter.ts +275 -0
- package/src/format/style.ts +278 -0
- package/src/index.ts +1 -1
- package/src/modules/activity.ts +38 -0
- package/src/modules/brand.ts +13 -0
- package/src/modules/cache.ts +23 -0
- package/src/modules/catalog.ts +124 -0
- package/src/modules/cloud.ts +74 -0
- package/src/modules/context.ts +33 -0
- package/src/modules/cost.ts +31 -0
- package/src/modules/deployment.ts +61 -0
- package/src/modules/development.ts +112 -0
- package/src/modules/directory.ts +151 -0
- package/src/modules/display.ts +14 -0
- package/src/modules/execution.ts +84 -0
- package/src/modules/extension-status.ts +93 -0
- package/src/modules/fill.ts +14 -0
- package/src/modules/git/branch.ts +31 -0
- package/src/modules/git/commit.ts +29 -0
- package/src/modules/git/metrics.ts +26 -0
- package/src/modules/git/runtime.ts +415 -0
- package/src/modules/git/state.ts +21 -0
- package/src/modules/git/status.ts +87 -0
- package/src/modules/git/worktree.ts +16 -0
- package/src/modules/github-pr.ts +24 -0
- package/src/modules/helpers.ts +5 -0
- package/src/modules/index.ts +31 -0
- package/src/modules/inspection.ts +138 -0
- package/src/modules/languages.ts +87 -0
- package/src/modules/model.ts +85 -0
- package/src/modules/package.ts +17 -0
- package/src/modules/provider.ts +13 -0
- package/src/modules/render.ts +166 -0
- package/src/modules/terminal.ts +60 -0
- package/src/modules/thinking.ts +13 -0
- package/src/modules/time.ts +20 -0
- package/src/modules/tokens.ts +18 -0
- package/src/modules/truncation.ts +37 -0
- package/src/modules/turn.ts +13 -0
- package/src/modules/types.ts +189 -0
- package/src/modules/workspace-helpers.ts +10 -0
- package/src/pi-starship.ts +619 -0
- 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/runtime/cloud.ts +166 -0
- package/src/runtime/command.ts +123 -0
- package/src/runtime/deployment.ts +201 -0
- package/src/runtime/development.ts +153 -0
- package/src/runtime/execution.ts +151 -0
- package/src/runtime/github-pr.ts +332 -0
- package/src/runtime/helpers.ts +274 -0
- package/src/runtime/languages.ts +205 -0
- package/src/runtime/package.ts +112 -0
- package/src/runtime/refresh-controller.ts +107 -0
- package/src/runtime/types.ts +63 -0
- package/src/runtime/workspace.ts +147 -0
- package/src/usage.ts +53 -0
- package/dist/chunks/chunk-CKNSOLSW.ts +0 -10
- package/dist/chunks/chunk-CKNSOLSW.ts.map +0 -7
- package/dist/chunks/chunk-G2GG2V6Q.ts +0 -218
- package/dist/chunks/chunk-G2GG2V6Q.ts.map +0 -7
- package/dist/chunks/chunk-Q6DLIM7H.ts +0 -2492
- package/dist/chunks/chunk-Q6DLIM7H.ts.map +0 -7
- package/dist/chunks/cloud-JBSZWTB6.ts +0 -142
- package/dist/chunks/cloud-JBSZWTB6.ts.map +0 -7
- package/dist/chunks/commands-BSQZ2R4M.ts +0 -757
- package/dist/chunks/commands-BSQZ2R4M.ts.map +0 -7
- package/dist/chunks/deployment-ZNYM4B6W.ts +0 -172
- package/dist/chunks/deployment-ZNYM4B6W.ts.map +0 -7
- package/dist/chunks/development-TNWZ5SRC.ts +0 -132
- package/dist/chunks/development-TNWZ5SRC.ts.map +0 -7
- package/dist/chunks/execution-QHAP4U33.ts +0 -132
- package/dist/chunks/execution-QHAP4U33.ts.map +0 -7
- package/dist/chunks/languages-DPWDCH6Q.ts +0 -184
- package/dist/chunks/languages-DPWDCH6Q.ts.map +0 -7
- package/dist/chunks/package-MXN2YFLX.ts +0 -104
- package/dist/chunks/package-MXN2YFLX.ts.map +0 -7
- package/dist/pi-starship.ts +0 -1350
- package/dist/pi-starship.ts.map +0 -7
package/NOTICES.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# Notices
|
|
2
2
|
|
|
3
|
-
pi-starship's format
|
|
4
|
-
|
|
3
|
+
pi-starship's format, style behavior, and bundled preset color and layout treatments are based in
|
|
4
|
+
part on the preset documents emitted by Starship 1.26.0. The preset modules and TOML are adapted to
|
|
5
|
+
Pi's native runtime snapshots. pi-starship uses the `yaml` package to parse kubeconfig and OpenStack
|
|
6
|
+
metadata as inert local data.
|
|
5
7
|
|
|
6
8
|
## yaml
|
|
7
9
|
|
package/README.md
CHANGED
|
@@ -17,8 +17,9 @@ A native Pi footer configured with Starship-style TOML. It parses and renders fo
|
|
|
17
17
|
- Width-aware `$fill` alignment for native multiline left/right layouts.
|
|
18
18
|
- Footer rendering is pure: no subprocess, network, filesystem, timer, or environment work runs from `render()`.
|
|
19
19
|
- Multiline output wraps to the terminal width instead of truncating.
|
|
20
|
-
- Goal-oriented `/starship` menu with
|
|
21
|
-
|
|
20
|
+
- Goal-oriented `/starship` menu with every Starship 1.26 preset style plus a Pi-native Minimal
|
|
21
|
+
preset, footer explanation, searchable module inspection, configuration health, transactional
|
|
22
|
+
preview, and recovery.
|
|
22
23
|
|
|
23
24
|
## 📦 Install
|
|
24
25
|
|
|
@@ -26,7 +27,7 @@ A native Pi footer configured with Starship-style TOML. It parses and renders fo
|
|
|
26
27
|
pi install npm:@narumitw/pi-starship
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
Try it from a checkout
|
|
30
|
+
Try it directly from a checkout:
|
|
30
31
|
|
|
31
32
|
```bash
|
|
32
33
|
just try starship
|
|
@@ -64,9 +65,9 @@ on the next `session_start`, including `/reload` and session replacement. Editor
|
|
|
64
65
|
cancellation, component disposal, invalid drafts, write failures, and runtime application failures
|
|
65
66
|
preserve the previous file and effective footer.
|
|
66
67
|
|
|
67
|
-
The shallow main menu also exposes **Explain footer**, **Modules**, **Configuration**,
|
|
68
|
-
**Restore built-in…**. Explain footer uses the current immutable runtime snapshot to list
|
|
69
|
-
currently showing non-empty module once with its rendered value and description; it starts no new
|
|
68
|
+
The shallow main menu also exposes **Presets**, **Explain footer**, **Modules**, **Configuration**,
|
|
69
|
+
**Help**, and **Restore built-in…**. Explain footer uses the current immutable runtime snapshot to list
|
|
70
|
+
each currently showing non-empty module once with its rendered value and description; it starts no new
|
|
70
71
|
collection work. Modules opens a bounded searchable inspector for every registered module. Its
|
|
71
72
|
textual states distinguish **Showing**, **Empty**, **Disabled**, **Not in format**, and
|
|
72
73
|
**Unavailable** only when the current footer cannot provide an inspection snapshot. Module detail
|
|
@@ -75,12 +76,56 @@ variables, style fields, display rules, and the known reason for absent output.
|
|
|
75
76
|
read-only and never create or update the settings document.
|
|
76
77
|
|
|
77
78
|
Configuration combines state, source, path, health, and diagnostics. A healthy missing file is shown
|
|
78
|
-
as **Built-in defaults**,
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
as **Built-in defaults**, an exact bundled document is shown as its named preset, and **Built-in
|
|
80
|
+
fallback** is reserved for read or parse errors. Restore is disabled when no settings document exists
|
|
81
|
+
or the exact built-in document is already saved. For a custom or invalid document, Restore previews
|
|
82
|
+
the result and warns that the complete document,
|
|
81
83
|
including custom settings, unknown fields, and comments, will be replaced without a post-success
|
|
82
84
|
backup before asking for confirmation.
|
|
83
85
|
|
|
86
|
+
### 🎛️ Presets
|
|
87
|
+
|
|
88
|
+
Choose **Presets** from `/starship` to browse complete Pi-native starting points. The catalog adapts
|
|
89
|
+
all styles listed by `starship preset --list` in Starship 1.26.0, plus a Pi-specific Minimal option.
|
|
90
|
+
Colors, separators, typography, and layout follow the named Starship preset; modules are deliberately
|
|
91
|
+
selected for Pi's model, thinking, workspace, Git, activity, context, and time snapshots.
|
|
92
|
+
|
|
93
|
+
| Preset | Adapted visual treatment | Font requirement |
|
|
94
|
+
| --- | --- | --- |
|
|
95
|
+
| **Minimal** | Compact Pi essentials | Standard Unicode |
|
|
96
|
+
| **Bracketed Segments** | Balanced Pi and Git information in brackets | Standard Unicode |
|
|
97
|
+
| **Catppuccin Powerline** | Connected Catppuccin Mocha blocks; other Catppuccin palettes remain in the document for customization | Nerd Font |
|
|
98
|
+
| **Gruvbox Rainbow** | Warm Gruvbox connected segments | Nerd Font |
|
|
99
|
+
| **Jetpack** | Airy geometric activity/context and workspace columns joined by fill | Standard Unicode |
|
|
100
|
+
| **Nerd Font Symbols** | Balanced default layout with icon-rich symbols | Nerd Font |
|
|
101
|
+
| **No Empty Icons** | Conditional text labels that cannot appear without their values | Standard Unicode |
|
|
102
|
+
| **No Nerd Font** | Portable Unicode symbols without private-use glyphs | Standard Unicode |
|
|
103
|
+
| **No Runtime Versions** | Presence indicators without model or thinking details | Standard Unicode |
|
|
104
|
+
| **Pastel Powerline** | Connected magenta, coral, orange, blue, teal, and navy blocks | Nerd Font |
|
|
105
|
+
| **Plain Text Symbols** | Plain words replace pictograms | Standard Unicode |
|
|
106
|
+
| **Pure Preset** | Clean two-line workspace and session context | Standard Unicode |
|
|
107
|
+
| **Tokyo Night** | Connected cool blue Tokyo Night blocks | Nerd Font |
|
|
108
|
+
|
|
109
|
+
The preset cursor is a live footer preview. Opening the picker and moving with Up/Down, Page Up/Down,
|
|
110
|
+
Home, or End temporarily renders the selected preset in the actual footer without writing settings or
|
|
111
|
+
starting new collectors. Press Enter to start the named preset's replacement confirmation, or press
|
|
112
|
+
`e` to customize the selected complete TOML document before its normal editor preview and
|
|
113
|
+
confirmation. Escape returns to the main menu, while Ctrl+C closes the complete workflow; both restore
|
|
114
|
+
the previously effective footer.
|
|
115
|
+
|
|
116
|
+
Presets are complete documents, not overlays. Applying one replaces `pi-starship.toml`, including
|
|
117
|
+
custom settings, unknown fields, and comments, only after a separate confirmation; no post-success
|
|
118
|
+
backup is kept. Cursor movement, confirmation cancellation, disposal, validation failure, write
|
|
119
|
+
failure, and runtime-apply failure retain the previous valid document and effective footer. Exact
|
|
120
|
+
unedited matches are shown as **Currently applied** and cannot be redundantly selected; editing any
|
|
121
|
+
byte makes the document custom again. **Restore built-in…** remains the deterministic recovery path.
|
|
122
|
+
|
|
123
|
+
The bundled presets use only pi-starship's local Pi and Git snapshot modules. They do not enable the
|
|
124
|
+
GitHub PR query, cloud/deployment readers, or optional command-backed workspace collectors. They are
|
|
125
|
+
Pi-native adaptations of the color and format treatments emitted by Starship 1.26.0; they do not copy
|
|
126
|
+
Starship's module selections because Pi exposes different runtime information. There is no
|
|
127
|
+
`/starship preset` textual route and no remote preset download.
|
|
128
|
+
|
|
84
129
|
### 📝 Example
|
|
85
130
|
|
|
86
131
|
```toml
|
|
@@ -593,10 +638,11 @@ Package's explicitly documented Cargo lookup is the only ancestor walk and is ca
|
|
|
593
638
|
| `/starship status` | Show config source/path and diagnostics |
|
|
594
639
|
| `/starship help` | Show command and configuration help |
|
|
595
640
|
|
|
596
|
-
The standard main menu keeps
|
|
597
|
-
**Modules**, **Configuration**, **Help**, and **Restore built-in…**. It shows whether
|
|
598
|
-
built-in defaults, a saved built-in document, a custom document, or an
|
|
599
|
-
|
|
641
|
+
The standard main menu keeps seven goals on one level: **Customize footer**, **Presets**,
|
|
642
|
+
**Explain footer**, **Modules**, **Configuration**, **Help**, and **Restore built-in…**. It shows whether
|
|
643
|
+
the footer uses built-in defaults, a saved built-in document, a named preset, a custom document, or an
|
|
644
|
+
error-driven fallback,
|
|
645
|
+
together with the current health. Presets, Explain, and Modules are menu-only paths; they do not add
|
|
600
646
|
textual subcommands or change RPC, print, or JSON protocols. Restore remains last and unavailable
|
|
601
647
|
when there is no document to replace.
|
|
602
648
|
|
|
@@ -630,13 +676,13 @@ Keep `extension_status` last in the catalog so arbitrary third-party statuses fo
|
|
|
630
676
|
|
|
631
677
|
## 🗂️ Package layout
|
|
632
678
|
|
|
633
|
-
- `src/index.ts` — thin Pi package entrypoint forwarding to the
|
|
634
|
-
- `dist/` — generated split TypeScript runtime and source maps loaded through Pi's Jiti aliases.
|
|
635
|
-
- `scripts/build-runtime.mjs` — deterministic runtime bundler and eager-import boundary validator.
|
|
679
|
+
- `src/index.ts` — thin Pi package entrypoint forwarding to the source runtime.
|
|
636
680
|
- `src/pi-starship.ts` — authoritative extension lifecycle, cached refresh binding, live preview, and footer.
|
|
637
681
|
- `src/usage.ts` — native-aligned session usage and cache aggregation.
|
|
638
682
|
- `src/command-contract.ts` — lightweight command routes and completions loaded at startup.
|
|
639
683
|
- `src/commands.ts` — lazily loaded menu, preview/confirmation flow, diagnostics, and compatibility routes.
|
|
684
|
+
- `src/command-preset-picker.ts` — lifecycle-owned preset cursor and temporary footer-preview UI.
|
|
685
|
+
- `src/presets/` — bundled complete TOML documents and stable preset metadata.
|
|
640
686
|
- `src/command-inspector.ts` — adaptive Explain and searchable read-only module inspection surfaces.
|
|
641
687
|
- `src/command-preview.ts` — adaptive, scrollable, keybinding-aware preview action surface.
|
|
642
688
|
- `src/config.ts` — TOML loading, draft validation, defaults, atomic persistence, and rollback.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-starship",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"description": "Native Starship-style TOML statusline for the Pi coding agent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
"toml"
|
|
16
16
|
],
|
|
17
17
|
"files": [
|
|
18
|
-
"src
|
|
19
|
-
"dist",
|
|
18
|
+
"src",
|
|
20
19
|
"README.md",
|
|
21
20
|
"LICENSE",
|
|
22
21
|
"NOTICES.md"
|
|
@@ -26,11 +25,12 @@
|
|
|
26
25
|
"./src/index.ts"
|
|
27
26
|
]
|
|
28
27
|
},
|
|
28
|
+
"piExtension": {
|
|
29
|
+
"lifecycle": "stable"
|
|
30
|
+
},
|
|
29
31
|
"scripts": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"format": "biome check --write --vcs-use-ignore-file=false src test scripts package.json tsconfig.json README.md NOTICES.md",
|
|
33
|
-
"prepack": "npm run build",
|
|
32
|
+
"check": "biome check --vcs-use-ignore-file=false src test package.json tsconfig.json README.md NOTICES.md && npm run typecheck",
|
|
33
|
+
"format": "biome check --write --vcs-use-ignore-file=false src test package.json tsconfig.json README.md NOTICES.md",
|
|
34
34
|
"typecheck": "tsc --noEmit"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
@@ -44,15 +44,14 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@biomejs/biome": "2.5.7",
|
|
47
|
-
"@earendil-works/pi-coding-agent": "0.
|
|
48
|
-
"@earendil-works/pi-tui": "0.
|
|
47
|
+
"@earendil-works/pi-coding-agent": "0.84.1",
|
|
48
|
+
"@earendil-works/pi-tui": "0.84.1",
|
|
49
49
|
"@types/node": "26.1.2",
|
|
50
|
-
"esbuild": "0.28.1",
|
|
51
50
|
"typescript": "7.0.2"
|
|
52
51
|
},
|
|
53
52
|
"repository": {
|
|
54
53
|
"type": "git",
|
|
55
54
|
"url": "https://github.com/narumiruna/pi-extensions",
|
|
56
|
-
"directory": "
|
|
55
|
+
"directory": "packages/pi-starship"
|
|
57
56
|
}
|
|
58
57
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AutocompleteItem } from "@earendil-works/pi-tui";
|
|
2
|
+
|
|
3
|
+
export const STARSHIP_SUBCOMMANDS: readonly AutocompleteItem[] = [
|
|
4
|
+
{ value: "settings", label: "settings", description: "Customize the footer TOML" },
|
|
5
|
+
{ value: "status", label: "status", description: "Show configuration health and source" },
|
|
6
|
+
{ value: "help", label: "help", description: "Show configuration help" },
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
export function completeStarshipArguments(prefix: string): AutocompleteItem[] | null {
|
|
10
|
+
const normalized = prefix.trim().toLowerCase();
|
|
11
|
+
const matches = STARSHIP_SUBCOMMANDS.filter((item) => item.value.startsWith(normalized));
|
|
12
|
+
return matches.length > 0 ? [...matches] : null;
|
|
13
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
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
|
+
import type { StatuslineInspection } from "./modules/inspection.js";
|
|
5
|
+
|
|
6
|
+
const RESERVED_HOST_ROWS = 3;
|
|
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[] {
|
|
81
|
+
if (!inspection) {
|
|
82
|
+
return wrapLines(
|
|
83
|
+
[
|
|
84
|
+
"Footer inspection is unavailable until the TUI footer is ready.",
|
|
85
|
+
"No collection work was started.",
|
|
86
|
+
],
|
|
87
|
+
width,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
if (inspection.showing.length === 0) {
|
|
91
|
+
return wrapLines(
|
|
92
|
+
[
|
|
93
|
+
"No modules are currently showing.",
|
|
94
|
+
"Open Modules to inspect empty, disabled, or unreachable modules.",
|
|
95
|
+
],
|
|
96
|
+
width,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
const lines = inspection.showing.flatMap((module, index) => [
|
|
100
|
+
...(index > 0 ? [""] : []),
|
|
101
|
+
module.name,
|
|
102
|
+
...previewLines(module.preview),
|
|
103
|
+
module.description,
|
|
104
|
+
]);
|
|
105
|
+
return wrapLines(lines, width);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function previewLines(preview: string): string[] {
|
|
109
|
+
const lines = preview ? preview.split("\n") : ["(no text)"];
|
|
110
|
+
return lines.map((line, index) => `${index === 0 ? "Value: " : " "}${line}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function wrapLines(lines: readonly string[], width: number): string[] {
|
|
114
|
+
return lines.flatMap((line) => {
|
|
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("/");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function safeDisplayText(value: string): string {
|
|
190
|
+
return Array.from(stripVTControlCharacters(value), (character) => {
|
|
191
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
192
|
+
return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? "" : character;
|
|
193
|
+
}).join("");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function clamp(value: number, minimum: number, maximum: number): number {
|
|
197
|
+
return Math.max(minimum, Math.min(value, maximum));
|
|
198
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from "node:util";
|
|
2
|
+
import {
|
|
3
|
+
DynamicBorder,
|
|
4
|
+
type ExtensionCommandContext,
|
|
5
|
+
type KeybindingsManager,
|
|
6
|
+
} from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import {
|
|
8
|
+
Container,
|
|
9
|
+
Key,
|
|
10
|
+
matchesKey,
|
|
11
|
+
type SelectItem,
|
|
12
|
+
SelectList,
|
|
13
|
+
Text,
|
|
14
|
+
} from "@earendil-works/pi-tui";
|
|
15
|
+
import { runCustomInteraction } from "@narumitw/pi-tui-kit";
|
|
16
|
+
import type { StarshipPreset } from "./presets/catalog.js";
|
|
17
|
+
|
|
18
|
+
export type PresetPickerResult =
|
|
19
|
+
| { kind: "apply"; presetId: StarshipPreset["id"] }
|
|
20
|
+
| { kind: "customize"; presetId: StarshipPreset["id"] }
|
|
21
|
+
| { kind: "back" }
|
|
22
|
+
| { kind: "close" };
|
|
23
|
+
|
|
24
|
+
export interface PresetPickerOptions {
|
|
25
|
+
presets: readonly StarshipPreset[];
|
|
26
|
+
activePresetId?: StarshipPreset["id"];
|
|
27
|
+
initialPresetId?: StarshipPreset["id"];
|
|
28
|
+
signal: AbortSignal;
|
|
29
|
+
isCurrent(): boolean;
|
|
30
|
+
preview(preset: StarshipPreset): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function showPresetPicker(
|
|
34
|
+
ctx: ExtensionCommandContext,
|
|
35
|
+
options: PresetPickerOptions,
|
|
36
|
+
): Promise<PresetPickerResult> {
|
|
37
|
+
const items: SelectItem[] = options.presets.map((preset) => ({
|
|
38
|
+
value: preset.id,
|
|
39
|
+
label: `${preset.id === options.activePresetId ? "[-] " : ""}${preset.label}`,
|
|
40
|
+
description:
|
|
41
|
+
preset.id === options.activePresetId
|
|
42
|
+
? `Currently applied · ${preset.description}`
|
|
43
|
+
: preset.description,
|
|
44
|
+
}));
|
|
45
|
+
const initialIndex = Math.max(
|
|
46
|
+
0,
|
|
47
|
+
options.presets.findIndex(
|
|
48
|
+
(preset) => preset.id === (options.initialPresetId ?? options.activePresetId),
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
const result = await runCustomInteraction<PresetPickerResult>(ctx, {
|
|
52
|
+
signal: options.signal,
|
|
53
|
+
isCurrent: options.isCurrent,
|
|
54
|
+
create({ tui, theme, keybindings, complete }) {
|
|
55
|
+
const container = new Container();
|
|
56
|
+
const topBorder = new DynamicBorder((text: string) => theme.fg("accent", text));
|
|
57
|
+
const bottomBorder = new DynamicBorder((text: string) => theme.fg("accent", text));
|
|
58
|
+
const title = new Text("", 1, 0);
|
|
59
|
+
const detail = new Text("", 1, 0);
|
|
60
|
+
const hint = new Text("", 1, 0);
|
|
61
|
+
const viewportSize = Math.min(items.length, 10);
|
|
62
|
+
const list = new SelectList(items, viewportSize, {
|
|
63
|
+
selectedPrefix: (text) => theme.fg("accent", text),
|
|
64
|
+
selectedText: (text) => theme.fg("accent", text),
|
|
65
|
+
description: (text) => theme.fg("muted", text),
|
|
66
|
+
scrollInfo: (text) => theme.fg("dim", text),
|
|
67
|
+
noMatch: (text) => theme.fg("warning", text),
|
|
68
|
+
});
|
|
69
|
+
const selectedPreset = () => {
|
|
70
|
+
const id = list.getSelectedItem()?.value;
|
|
71
|
+
return options.presets.find((preset) => preset.id === id);
|
|
72
|
+
};
|
|
73
|
+
const updateSelectedText = () => {
|
|
74
|
+
const preset = selectedPreset();
|
|
75
|
+
if (!preset) return;
|
|
76
|
+
detail.setText(
|
|
77
|
+
theme.fg(
|
|
78
|
+
"muted",
|
|
79
|
+
`Selected: ${preset.label} · ${preset.requiresNerdFont ? "requires Nerd Font" : "font-safe"}`,
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
const previewSelected = () => {
|
|
84
|
+
const preset = selectedPreset();
|
|
85
|
+
if (!preset) return;
|
|
86
|
+
updateSelectedText();
|
|
87
|
+
options.preview(preset);
|
|
88
|
+
};
|
|
89
|
+
const updateThemedText = () => {
|
|
90
|
+
const current =
|
|
91
|
+
options.presets.find((preset) => preset.id === options.activePresetId)?.label ??
|
|
92
|
+
"Custom configuration";
|
|
93
|
+
title.setText(theme.fg("accent", theme.bold(`Presets · current: ${current}`)));
|
|
94
|
+
hint.setText(theme.fg("dim", pickerHint(keybindings)));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
let selectedIndex = initialIndex;
|
|
98
|
+
const select = (index: number) => {
|
|
99
|
+
if (items.length === 0) return;
|
|
100
|
+
selectedIndex = Math.max(0, Math.min(index, items.length - 1));
|
|
101
|
+
list.setSelectedIndex(selectedIndex);
|
|
102
|
+
previewSelected();
|
|
103
|
+
};
|
|
104
|
+
const move = (delta: number) => {
|
|
105
|
+
if (items.length === 0) return;
|
|
106
|
+
select((selectedIndex + delta + items.length) % items.length);
|
|
107
|
+
};
|
|
108
|
+
const applySelected = () => {
|
|
109
|
+
const preset = selectedPreset();
|
|
110
|
+
if (preset && preset.id !== options.activePresetId) {
|
|
111
|
+
complete({ kind: "apply", presetId: preset.id });
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
list.setSelectedIndex(initialIndex);
|
|
115
|
+
container.addChild(topBorder);
|
|
116
|
+
container.addChild(title);
|
|
117
|
+
container.addChild(list);
|
|
118
|
+
container.addChild(detail);
|
|
119
|
+
container.addChild(hint);
|
|
120
|
+
container.addChild(bottomBorder);
|
|
121
|
+
updateThemedText();
|
|
122
|
+
previewSelected();
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
render: (width: number) => container.render(width),
|
|
126
|
+
invalidate() {
|
|
127
|
+
container.invalidate();
|
|
128
|
+
updateThemedText();
|
|
129
|
+
updateSelectedText();
|
|
130
|
+
},
|
|
131
|
+
handleInput(data: string) {
|
|
132
|
+
if (matchesKey(data, Key.ctrl("c"))) {
|
|
133
|
+
complete({ kind: "close" });
|
|
134
|
+
} else if (keybindings.matches(data, "tui.select.cancel")) {
|
|
135
|
+
complete({ kind: "back" });
|
|
136
|
+
} else if (keybindings.matches(data, "tui.select.up")) {
|
|
137
|
+
move(-1);
|
|
138
|
+
} else if (keybindings.matches(data, "tui.select.down")) {
|
|
139
|
+
move(1);
|
|
140
|
+
} else if (keybindings.matches(data, "tui.select.pageUp")) {
|
|
141
|
+
select(selectedIndex - Math.max(1, viewportSize));
|
|
142
|
+
} else if (keybindings.matches(data, "tui.select.pageDown")) {
|
|
143
|
+
select(selectedIndex + Math.max(1, viewportSize));
|
|
144
|
+
} else if (matchesKey(data, Key.home)) {
|
|
145
|
+
select(0);
|
|
146
|
+
} else if (matchesKey(data, Key.end)) {
|
|
147
|
+
select(items.length - 1);
|
|
148
|
+
} else if (data === "e" || data === "E") {
|
|
149
|
+
const preset = selectedPreset();
|
|
150
|
+
if (preset) complete({ kind: "customize", presetId: preset.id });
|
|
151
|
+
} else if (keybindings.matches(data, "tui.select.confirm")) {
|
|
152
|
+
applySelected();
|
|
153
|
+
}
|
|
154
|
+
tui.requestRender();
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
return result.kind === "completed" ? result.value : { kind: "close" };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function pickerHint(keybindings: Pick<KeybindingsManager, "getKeys">): string {
|
|
163
|
+
const up = bindingText(keybindings, "tui.select.up");
|
|
164
|
+
const down = bindingText(keybindings, "tui.select.down");
|
|
165
|
+
const confirm = bindingText(keybindings, "tui.select.confirm");
|
|
166
|
+
const cancel = bindingText(keybindings, "tui.select.cancel", "ctrl+c");
|
|
167
|
+
const pageUp = bindingText(keybindings, "tui.select.pageUp");
|
|
168
|
+
const pageDown = bindingText(keybindings, "tui.select.pageDown");
|
|
169
|
+
return [
|
|
170
|
+
...(up || down ? [`${[up, down].filter(Boolean).join("/")} live preview`] : []),
|
|
171
|
+
...(confirm ? [`${confirm} apply`] : []),
|
|
172
|
+
"e customize",
|
|
173
|
+
...(cancel ? [`${cancel} back`] : []),
|
|
174
|
+
"ctrl+c close",
|
|
175
|
+
...(pageUp || pageDown ? [`${[pageUp, pageDown].filter(Boolean).join("/")} page preview`] : []),
|
|
176
|
+
].join(" • ");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function bindingText(
|
|
180
|
+
keybindings: Pick<KeybindingsManager, "getKeys">,
|
|
181
|
+
binding: Parameters<KeybindingsManager["getKeys"]>[0],
|
|
182
|
+
excluded?: string,
|
|
183
|
+
): string {
|
|
184
|
+
return keybindings
|
|
185
|
+
.getKeys(binding)
|
|
186
|
+
.filter((key) => key !== excluded)
|
|
187
|
+
.map((key) => {
|
|
188
|
+
if (key === "up") return "↑";
|
|
189
|
+
if (key === "down") return "↓";
|
|
190
|
+
if (key === "escape") return "esc";
|
|
191
|
+
if (key === "return") return "enter";
|
|
192
|
+
return safeDisplayText(key);
|
|
193
|
+
})
|
|
194
|
+
.join("/");
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function safeDisplayText(value: string): string {
|
|
198
|
+
return Array.from(stripVTControlCharacters(value), (character) => {
|
|
199
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
200
|
+
const control = codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f);
|
|
201
|
+
return control ? "" : character;
|
|
202
|
+
}).join("");
|
|
203
|
+
}
|