@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/modules/cost.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveDisplayStyle } from "./display.js";
|
|
1
2
|
import { defineModule } from "./types.js";
|
|
2
3
|
|
|
3
4
|
export const costModule = defineModule({
|
|
@@ -6,9 +7,19 @@ export const costModule = defineModule({
|
|
|
6
7
|
defaults: {
|
|
7
8
|
format: "[ $symbol \\$$cost( $subscription) ]($style)",
|
|
8
9
|
symbol: "💸",
|
|
9
|
-
style: "
|
|
10
|
+
style: "none",
|
|
10
11
|
disabled: false,
|
|
11
12
|
},
|
|
13
|
+
displayDefaults: [
|
|
14
|
+
{ threshold: 0, style: "bold green", hidden: true },
|
|
15
|
+
{ threshold: 1, style: "bold yellow", hidden: false },
|
|
16
|
+
{ threshold: 5, style: "bold red", hidden: false },
|
|
17
|
+
],
|
|
18
|
+
styleVariables: ["style"],
|
|
19
|
+
resolveStyleVariables: ({ runtime, display }) => {
|
|
20
|
+
const style = resolveDisplayStyle(display, runtime.tokenTotals.cost);
|
|
21
|
+
return style === undefined ? undefined : { style };
|
|
22
|
+
},
|
|
12
23
|
values: ({ runtime }) => ({
|
|
13
24
|
cost: formatCost(runtime.tokenTotals.cost),
|
|
14
25
|
subscription: runtime.usingSubscription ? "(sub)" : "",
|
package/src/modules/directory.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ModuleDisplayConfig } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export function resolveDisplayStyle(
|
|
4
|
+
display: readonly ModuleDisplayConfig[],
|
|
5
|
+
value: number | null | undefined,
|
|
6
|
+
): string | undefined {
|
|
7
|
+
if (value === null || value === undefined || !Number.isFinite(value)) return undefined;
|
|
8
|
+
let selected: ModuleDisplayConfig | undefined;
|
|
9
|
+
for (const entry of display) {
|
|
10
|
+
if (entry.threshold > value) continue;
|
|
11
|
+
if (!selected || entry.threshold >= selected.threshold) selected = entry;
|
|
12
|
+
}
|
|
13
|
+
return selected && !selected.hidden ? selected.style : undefined;
|
|
14
|
+
}
|
package/src/modules/execution.ts
CHANGED
|
@@ -54,9 +54,20 @@ export const usernameModule = defineModule({
|
|
|
54
54
|
defaults: {
|
|
55
55
|
format: "[$user]($style) in ",
|
|
56
56
|
symbol: "",
|
|
57
|
-
style: "
|
|
57
|
+
style: "none",
|
|
58
58
|
disabled: false,
|
|
59
59
|
},
|
|
60
|
+
styleDefaults: {
|
|
61
|
+
style_user: "yellow bold",
|
|
62
|
+
style_root: "red bold",
|
|
63
|
+
},
|
|
64
|
+
styleVariables: ["style"],
|
|
65
|
+
resolveStyleVariables: ({ runtime, styles }) => ({
|
|
66
|
+
style:
|
|
67
|
+
runtime.workspace?.styleSelectors?.username === "root"
|
|
68
|
+
? (styles.style_root ?? "")
|
|
69
|
+
: (styles.style_user ?? ""),
|
|
70
|
+
}),
|
|
60
71
|
options: {
|
|
61
72
|
show_always: { kind: "boolean", default: false },
|
|
62
73
|
aliases: { kind: "string-map", default: {} },
|
package/src/modules/fill.ts
CHANGED
|
@@ -4,11 +4,17 @@ export const gitMetricsModule = defineModule({
|
|
|
4
4
|
name: "git_metrics",
|
|
5
5
|
variables: ["symbol", "added", "deleted"],
|
|
6
6
|
defaults: {
|
|
7
|
-
format: "[
|
|
7
|
+
format: "([+$added]($added_style) )([-$deleted]($deleted_style) )",
|
|
8
8
|
symbol: "",
|
|
9
|
-
style: "
|
|
9
|
+
style: "none",
|
|
10
10
|
disabled: true,
|
|
11
11
|
},
|
|
12
|
+
styleDefaults: {
|
|
13
|
+
added_style: "bold green",
|
|
14
|
+
deleted_style: "bold red",
|
|
15
|
+
},
|
|
16
|
+
styleVariables: ["added_style", "deleted_style"],
|
|
17
|
+
resolveStyleVariables: ({ styles }) => styles,
|
|
12
18
|
values: ({ runtime }) => {
|
|
13
19
|
const metrics = runtime.gitMetrics;
|
|
14
20
|
if (!metrics || (metrics.added === 0 && metrics.deleted === 0)) return undefined;
|
package/src/modules/git/state.ts
CHANGED
package/src/modules/github-pr.ts
CHANGED
package/src/modules/index.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
type CatalogModuleDefinition,
|
|
3
|
+
MODULE_DEFINITIONS,
|
|
4
|
+
MODULE_NAMES,
|
|
5
|
+
type ModuleName,
|
|
6
|
+
} from "./catalog.js";
|
|
2
7
|
export { formatExtensionStatus } from "./extension-status.js";
|
|
3
8
|
export { formatCount } from "./helpers.js";
|
|
9
|
+
export {
|
|
10
|
+
inspectStatuslineModules,
|
|
11
|
+
inspectUnavailableModules,
|
|
12
|
+
type ModuleInspection,
|
|
13
|
+
type ModuleInspectionState,
|
|
14
|
+
type StatuslineInspection,
|
|
15
|
+
} from "./inspection.js";
|
|
4
16
|
export { shortenModel } from "./model.js";
|
|
5
17
|
export { reachableModuleRequirements, renderStatusline } from "./render.js";
|
|
6
18
|
export type {
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from "node:util";
|
|
2
|
+
import type { StarshipConfig } from "../config.js";
|
|
3
|
+
import { formatVariables } from "../format/formatter.js";
|
|
4
|
+
import { MODULE_DEFINITIONS, type ModuleName } from "./catalog.js";
|
|
5
|
+
import { reachableModuleRequirements, renderStatusline } from "./render.js";
|
|
6
|
+
import type { StarshipRuntimeSnapshot } from "./types.js";
|
|
7
|
+
|
|
8
|
+
export type ModuleInspectionState =
|
|
9
|
+
| "Showing"
|
|
10
|
+
| "Empty"
|
|
11
|
+
| "Disabled"
|
|
12
|
+
| "Not in format"
|
|
13
|
+
| "Unavailable";
|
|
14
|
+
|
|
15
|
+
export interface ModuleInspection {
|
|
16
|
+
name: ModuleName;
|
|
17
|
+
description: string;
|
|
18
|
+
state: ModuleInspectionState;
|
|
19
|
+
preview: string;
|
|
20
|
+
variables: readonly string[];
|
|
21
|
+
styleFields: readonly string[];
|
|
22
|
+
displayRules: readonly string[];
|
|
23
|
+
rootReferenced: boolean;
|
|
24
|
+
reachable: boolean;
|
|
25
|
+
reason: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface StatuslineInspection {
|
|
29
|
+
modules: readonly ModuleInspection[];
|
|
30
|
+
showing: readonly ModuleInspection[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function inspectStatuslineModules(
|
|
34
|
+
config: StarshipConfig,
|
|
35
|
+
runtime: StarshipRuntimeSnapshot,
|
|
36
|
+
width = 80,
|
|
37
|
+
): StatuslineInspection {
|
|
38
|
+
const rendered = renderStatusline(config, runtime, width);
|
|
39
|
+
const requirements = reachableModuleRequirements(config);
|
|
40
|
+
const rootVariables = formatVariables(config.formatAst);
|
|
41
|
+
const includeAll = rootVariables.has("all");
|
|
42
|
+
const modules = MODULE_DEFINITIONS.map((definition): ModuleInspection => {
|
|
43
|
+
const module = config.modules[definition.name];
|
|
44
|
+
const reachable = requirements.has(definition.name);
|
|
45
|
+
const preview = plainPreview(
|
|
46
|
+
rendered.modules[definition.name].map((chunk) => chunk.text).join(""),
|
|
47
|
+
);
|
|
48
|
+
const state = module.disabled
|
|
49
|
+
? "Disabled"
|
|
50
|
+
: !reachable
|
|
51
|
+
? "Not in format"
|
|
52
|
+
: preview.length > 0
|
|
53
|
+
? "Showing"
|
|
54
|
+
: "Empty";
|
|
55
|
+
return moduleInspection(
|
|
56
|
+
config,
|
|
57
|
+
definition,
|
|
58
|
+
state,
|
|
59
|
+
preview,
|
|
60
|
+
includeAll || rootVariables.has(definition.name),
|
|
61
|
+
reachable,
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
modules,
|
|
66
|
+
showing: modules.filter((module) => module.state === "Showing"),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function inspectUnavailableModules(config: StarshipConfig): StatuslineInspection {
|
|
71
|
+
const requirements = reachableModuleRequirements(config);
|
|
72
|
+
const rootVariables = formatVariables(config.formatAst);
|
|
73
|
+
const includeAll = rootVariables.has("all");
|
|
74
|
+
return {
|
|
75
|
+
modules: MODULE_DEFINITIONS.map((definition) => {
|
|
76
|
+
const module = config.modules[definition.name];
|
|
77
|
+
const reachable = requirements.has(definition.name);
|
|
78
|
+
const state = module.disabled ? "Disabled" : reachable ? "Unavailable" : "Not in format";
|
|
79
|
+
return moduleInspection(
|
|
80
|
+
config,
|
|
81
|
+
definition,
|
|
82
|
+
state,
|
|
83
|
+
"",
|
|
84
|
+
includeAll || rootVariables.has(definition.name),
|
|
85
|
+
reachable,
|
|
86
|
+
);
|
|
87
|
+
}),
|
|
88
|
+
showing: [],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function moduleInspection(
|
|
93
|
+
config: StarshipConfig,
|
|
94
|
+
definition: (typeof MODULE_DEFINITIONS)[number],
|
|
95
|
+
state: ModuleInspectionState,
|
|
96
|
+
preview: string,
|
|
97
|
+
rootReferenced: boolean,
|
|
98
|
+
reachable: boolean,
|
|
99
|
+
): ModuleInspection {
|
|
100
|
+
const module = config.modules[definition.name];
|
|
101
|
+
return {
|
|
102
|
+
name: definition.name,
|
|
103
|
+
description: definition.description,
|
|
104
|
+
state,
|
|
105
|
+
preview,
|
|
106
|
+
variables: [...definition.variables],
|
|
107
|
+
styleFields: ["style", ...Object.keys(module.styles)],
|
|
108
|
+
displayRules: module.display.map(
|
|
109
|
+
(rule) => `${rule.threshold}: ${rule.hidden ? "hidden" : rule.style || "unstyled"}`,
|
|
110
|
+
),
|
|
111
|
+
rootReferenced,
|
|
112
|
+
reachable,
|
|
113
|
+
reason: inspectionReason(state),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function inspectionReason(state: ModuleInspectionState): string {
|
|
118
|
+
switch (state) {
|
|
119
|
+
case "Showing":
|
|
120
|
+
return "Rendered in the current footer.";
|
|
121
|
+
case "Empty":
|
|
122
|
+
return "Referenced by the root format, but the current snapshot produced no output.";
|
|
123
|
+
case "Disabled":
|
|
124
|
+
return "Disabled by this module's configuration.";
|
|
125
|
+
case "Not in format":
|
|
126
|
+
return "Not referenced by the root format or $all.";
|
|
127
|
+
case "Unavailable":
|
|
128
|
+
return "Current footer inspection is unavailable; no collector failure was inferred.";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function plainPreview(value: string): string {
|
|
133
|
+
return Array.from(stripVTControlCharacters(value), (character) => {
|
|
134
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
135
|
+
if (character === "\n") return character;
|
|
136
|
+
return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? " " : character;
|
|
137
|
+
}).join("");
|
|
138
|
+
}
|
package/src/modules/model.ts
CHANGED
package/src/modules/provider.ts
CHANGED
|
@@ -6,7 +6,7 @@ export const providerModule = defineModule({
|
|
|
6
6
|
defaults: {
|
|
7
7
|
format: "[$symbol $provider ]($style)",
|
|
8
8
|
symbol: "🔌",
|
|
9
|
-
style: "
|
|
9
|
+
style: "bold blue",
|
|
10
10
|
disabled: false,
|
|
11
11
|
},
|
|
12
12
|
values: ({ runtime }) => (runtime.model ? { provider: runtime.model.provider } : undefined),
|
package/src/modules/render.ts
CHANGED
|
@@ -24,12 +24,30 @@ export function renderStatusline(
|
|
|
24
24
|
}
|
|
25
25
|
for (const definition of MODULE_DEFINITIONS) {
|
|
26
26
|
const name = definition.name;
|
|
27
|
+
const module = config.modules[name];
|
|
27
28
|
const values = definition.values(valueContext(config, name, runtime));
|
|
28
29
|
if (!values) continue;
|
|
29
|
-
const
|
|
30
|
+
const styleVariables = definition.resolveStyleVariables
|
|
31
|
+
? definition.resolveStyleVariables({
|
|
32
|
+
runtime,
|
|
33
|
+
values,
|
|
34
|
+
style: module.style,
|
|
35
|
+
styles: module.styles,
|
|
36
|
+
display: module.display,
|
|
37
|
+
})
|
|
38
|
+
: { style: module.style };
|
|
39
|
+
if (!styleVariables) continue;
|
|
40
|
+
const contentValues = Object.fromEntries(
|
|
41
|
+
definition.variables.flatMap((variable) =>
|
|
42
|
+
variable !== "symbol" && Object.hasOwn(values, variable)
|
|
43
|
+
? [[variable, values[variable]]]
|
|
44
|
+
: [],
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
const rendered = renderModule(module, contentValues, styleVariables, palette);
|
|
30
48
|
modules[name] = rendered;
|
|
31
49
|
layoutModules[name] =
|
|
32
|
-
definition.layout === "fill" && !
|
|
50
|
+
definition.layout === "fill" && !module.disabled
|
|
33
51
|
? [{ type: "fill", pattern: rendered }]
|
|
34
52
|
: rendered;
|
|
35
53
|
}
|
|
@@ -65,12 +83,13 @@ function valueContext(
|
|
|
65
83
|
function renderModule(
|
|
66
84
|
module: ModuleConfig,
|
|
67
85
|
values: Readonly<Record<string, FormatValue>>,
|
|
86
|
+
styleVariables: Readonly<Record<string, string>>,
|
|
68
87
|
palette: Readonly<Record<string, string>>,
|
|
69
88
|
): StyledChunk[] {
|
|
70
89
|
if (module.disabled) return [];
|
|
71
90
|
return renderFormat(module.formatAst, {
|
|
72
91
|
variables: { symbol: module.symbol, ...values },
|
|
73
|
-
styleVariables
|
|
92
|
+
styleVariables,
|
|
74
93
|
palette,
|
|
75
94
|
}).filter((chunk): chunk is StyledChunk => !isFillChunk(chunk));
|
|
76
95
|
}
|
package/src/modules/thinking.ts
CHANGED
package/src/modules/time.ts
CHANGED
package/src/modules/tokens.ts
CHANGED
package/src/modules/turn.ts
CHANGED
package/src/modules/types.ts
CHANGED
|
@@ -73,6 +73,7 @@ export interface GitSnapshot {
|
|
|
73
73
|
|
|
74
74
|
export interface WorkspaceSnapshot {
|
|
75
75
|
modules: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
76
|
+
styleSelectors?: Readonly<Record<string, string>>;
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
export interface StarshipRuntimeSnapshot {
|
|
@@ -138,6 +139,12 @@ export type ModuleOptionSchema =
|
|
|
138
139
|
| { kind: "string-array"; default: readonly string[]; allowNegative?: boolean }
|
|
139
140
|
| { kind: "string-map"; default: Readonly<Record<string, string>> };
|
|
140
141
|
|
|
142
|
+
export interface ModuleDisplayConfig {
|
|
143
|
+
threshold: number;
|
|
144
|
+
style: string;
|
|
145
|
+
hidden: boolean;
|
|
146
|
+
}
|
|
147
|
+
|
|
141
148
|
export interface ModuleDefaults {
|
|
142
149
|
format: string;
|
|
143
150
|
symbol: string;
|
|
@@ -145,10 +152,22 @@ export interface ModuleDefaults {
|
|
|
145
152
|
disabled: boolean;
|
|
146
153
|
}
|
|
147
154
|
|
|
155
|
+
export interface ModuleStyleContext {
|
|
156
|
+
runtime: StarshipRuntimeSnapshot;
|
|
157
|
+
values: Readonly<Record<string, string>>;
|
|
158
|
+
style: string;
|
|
159
|
+
styles: Readonly<Record<string, string>>;
|
|
160
|
+
display: readonly ModuleDisplayConfig[];
|
|
161
|
+
}
|
|
162
|
+
|
|
148
163
|
export interface ModuleDefinition<Name extends string> {
|
|
149
164
|
name: Name;
|
|
150
165
|
variables: readonly string[];
|
|
151
166
|
defaults: ModuleDefaults;
|
|
167
|
+
styleDefaults?: Readonly<Record<string, string>>;
|
|
168
|
+
displayDefaults?: readonly ModuleDisplayConfig[];
|
|
169
|
+
styleVariables?: readonly string[];
|
|
170
|
+
resolveStyleVariables?(context: ModuleStyleContext): Readonly<Record<string, string>> | undefined;
|
|
152
171
|
options?: Readonly<Record<string, ModuleOptionSchema>>;
|
|
153
172
|
layout?: "fill";
|
|
154
173
|
values(context: ModuleValueContext): Record<string, string> | undefined;
|
package/src/pi-starship.ts
CHANGED
|
@@ -17,9 +17,11 @@ import { gitSnapshotEqual, readGitSnapshot } from "./modules/git/runtime.js";
|
|
|
17
17
|
import {
|
|
18
18
|
type GithubPrSnapshot,
|
|
19
19
|
type GitSnapshot,
|
|
20
|
+
inspectStatuslineModules,
|
|
20
21
|
reachableModuleRequirements,
|
|
21
22
|
renderStatusline,
|
|
22
23
|
type StarshipRuntimeSnapshot,
|
|
24
|
+
type StatuslineInspection,
|
|
23
25
|
type WorkspaceSnapshot,
|
|
24
26
|
} from "./modules/index.js";
|
|
25
27
|
import { execWorkspaceCommand } from "./runtime/command.js";
|
|
@@ -48,6 +50,8 @@ interface RuntimeState {
|
|
|
48
50
|
workspace?: WorkspaceSnapshot;
|
|
49
51
|
requestRender?: () => void;
|
|
50
52
|
renderPreview?: (loaded: LoadedStarshipConfig, width: number) => string[];
|
|
53
|
+
inspect?: (loaded: LoadedStarshipConfig) => StatuslineInspection;
|
|
54
|
+
footerWidth?: number;
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
interface RefreshTarget {
|
|
@@ -242,6 +246,8 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
242
246
|
runtime.workspace = undefined;
|
|
243
247
|
runtime.requestRender = undefined;
|
|
244
248
|
runtime.renderPreview = undefined;
|
|
249
|
+
runtime.inspect = undefined;
|
|
250
|
+
runtime.footerWidth = undefined;
|
|
245
251
|
activeTarget = ctx.mode === "tui" ? target : undefined;
|
|
246
252
|
ctx.ui.setStatus("starship", undefined);
|
|
247
253
|
if (!activeTarget || !loaded) return;
|
|
@@ -258,6 +264,12 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
258
264
|
width,
|
|
259
265
|
);
|
|
260
266
|
};
|
|
267
|
+
runtime.inspect = (current) =>
|
|
268
|
+
inspectStatuslineModules(
|
|
269
|
+
current.config,
|
|
270
|
+
runtimeSnapshot(ctx, footerData, runtime),
|
|
271
|
+
runtime.footerWidth ?? 80,
|
|
272
|
+
);
|
|
261
273
|
const unsubscribe = footerData.onBranchChange(() => {
|
|
262
274
|
if (!isActiveTarget(target)) return;
|
|
263
275
|
runtime.git = undefined;
|
|
@@ -292,10 +304,13 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
292
304
|
runtime.workspace = undefined;
|
|
293
305
|
runtime.requestRender = undefined;
|
|
294
306
|
runtime.renderPreview = undefined;
|
|
307
|
+
runtime.inspect = undefined;
|
|
308
|
+
runtime.footerWidth = undefined;
|
|
295
309
|
}
|
|
296
310
|
},
|
|
297
311
|
invalidate() {},
|
|
298
312
|
render(width: number): string[] {
|
|
313
|
+
runtime.footerWidth = width;
|
|
299
314
|
if (!loaded) return [];
|
|
300
315
|
const snapshot = runtimeSnapshot(ctx, footerData, runtime);
|
|
301
316
|
return wrapFormattedStatusline(
|
|
@@ -313,6 +328,10 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
313
328
|
registerStarshipCommand(pi, {
|
|
314
329
|
settingsPath: configPath,
|
|
315
330
|
getLoaded: () => loaded ?? loadStarshipConfig(configPath),
|
|
331
|
+
getInspection: () => {
|
|
332
|
+
const current = loaded ?? loadStarshipConfig(configPath);
|
|
333
|
+
return runtime.inspect?.(current);
|
|
334
|
+
},
|
|
316
335
|
getMenuOwner: () => {
|
|
317
336
|
const generation = sessionGeneration;
|
|
318
337
|
return {
|
|
@@ -371,6 +390,8 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
371
390
|
runtime.workspace = undefined;
|
|
372
391
|
runtime.requestRender = undefined;
|
|
373
392
|
runtime.renderPreview = undefined;
|
|
393
|
+
runtime.inspect = undefined;
|
|
394
|
+
runtime.footerWidth = undefined;
|
|
374
395
|
ctx.ui.setFooter(undefined);
|
|
375
396
|
ctx.ui.setStatus("starship", undefined);
|
|
376
397
|
});
|
package/src/runtime/execution.ts
CHANGED
|
@@ -6,14 +6,23 @@ import {
|
|
|
6
6
|
optionStrings,
|
|
7
7
|
safeMetadata,
|
|
8
8
|
} from "./helpers.js";
|
|
9
|
-
import
|
|
9
|
+
import {
|
|
10
|
+
type CollectorContext,
|
|
11
|
+
type MutableModuleSnapshot,
|
|
12
|
+
PRIVATE_STYLE_SELECTOR,
|
|
13
|
+
} from "./types.js";
|
|
10
14
|
|
|
11
15
|
export async function collectExecution(context: CollectorContext): Promise<MutableModuleSnapshot> {
|
|
12
16
|
if (context.input.reason === "periodic" && context.input.previous) {
|
|
13
17
|
const retained: MutableModuleSnapshot = {};
|
|
14
18
|
for (const name of ["os", "container", "hostname", "username"] as const) {
|
|
15
19
|
const values = context.input.previous.modules[name];
|
|
16
|
-
if (context.needs(name)
|
|
20
|
+
if (!context.needs(name) || !values) continue;
|
|
21
|
+
const selector = context.input.previous.styleSelectors?.[name];
|
|
22
|
+
retained[name] = {
|
|
23
|
+
...values,
|
|
24
|
+
...(selector === undefined ? {} : { [PRIVATE_STYLE_SELECTOR]: selector }),
|
|
25
|
+
};
|
|
17
26
|
}
|
|
18
27
|
return retained;
|
|
19
28
|
}
|
|
@@ -116,7 +125,10 @@ function usernameValues(context: CollectorContext): Record<string, string> | und
|
|
|
116
125
|
) {
|
|
117
126
|
return undefined;
|
|
118
127
|
}
|
|
119
|
-
return {
|
|
128
|
+
return {
|
|
129
|
+
user: exactAlias(user, optionMap(context, "username", "aliases")) ?? user,
|
|
130
|
+
[PRIVATE_STYLE_SELECTOR]: privileged ? "root" : "user",
|
|
131
|
+
};
|
|
120
132
|
}
|
|
121
133
|
|
|
122
134
|
function isSsh(context: CollectorContext): boolean {
|
package/src/runtime/types.ts
CHANGED
package/src/runtime/workspace.ts
CHANGED
|
@@ -8,11 +8,12 @@ import { collectExecution } from "./execution.js";
|
|
|
8
8
|
import { createFileSystem } from "./helpers.js";
|
|
9
9
|
import { collectLanguages } from "./languages.js";
|
|
10
10
|
import { collectPackage } from "./package.js";
|
|
11
|
-
import
|
|
12
|
-
CollectorContext,
|
|
13
|
-
MutableModuleSnapshot,
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
import {
|
|
12
|
+
type CollectorContext,
|
|
13
|
+
type MutableModuleSnapshot,
|
|
14
|
+
PRIVATE_STYLE_SELECTOR,
|
|
15
|
+
type WorkspaceEntry,
|
|
16
|
+
type WorkspaceRefreshInput,
|
|
16
17
|
} from "./types.js";
|
|
17
18
|
|
|
18
19
|
export { parseTerraformVersion } from "./deployment.js";
|
|
@@ -108,6 +109,19 @@ function mergeModules(target: MutableModuleSnapshot, source: MutableModuleSnapsh
|
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
function freezeSnapshot(modules: MutableModuleSnapshot): WorkspaceSnapshot {
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
const styleSelectors: Record<string, string> = {};
|
|
113
|
+
for (const [name, values] of Object.entries(modules)) {
|
|
114
|
+
const selector = Object.hasOwn(values, PRIVATE_STYLE_SELECTOR)
|
|
115
|
+
? values[PRIVATE_STYLE_SELECTOR]
|
|
116
|
+
: undefined;
|
|
117
|
+
delete values[PRIVATE_STYLE_SELECTOR];
|
|
118
|
+
if (selector !== undefined) styleSelectors[name] = selector;
|
|
119
|
+
Object.freeze(values);
|
|
120
|
+
}
|
|
121
|
+
return Object.freeze({
|
|
122
|
+
modules: Object.freeze(modules),
|
|
123
|
+
...(Object.keys(styleSelectors).length > 0
|
|
124
|
+
? { styleSelectors: Object.freeze(styleSelectors) }
|
|
125
|
+
: {}),
|
|
126
|
+
});
|
|
113
127
|
}
|