@narumitw/pi-starship 0.49.3 → 0.49.4
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 +2 -4
- package/package.json +4 -8
- package/src/command-contract.ts +13 -0
- package/src/command-inspector.ts +198 -0
- package/src/command-preview.ts +206 -0
- package/src/commands.ts +575 -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 +609 -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
|
@@ -1,2492 +0,0 @@
|
|
|
1
|
-
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
-
// @ts-nocheck -- generated JavaScript uses a .ts extension so Pi routes chunks through Jiti.
|
|
3
|
-
|
|
4
|
-
// src/command-contract.ts
|
|
5
|
-
var STARSHIP_SUBCOMMANDS = [
|
|
6
|
-
{ value: "settings", label: "settings", description: "Customize the footer TOML" },
|
|
7
|
-
{ value: "status", label: "status", description: "Show configuration health and source" },
|
|
8
|
-
{ value: "help", label: "help", description: "Show configuration help" }
|
|
9
|
-
];
|
|
10
|
-
function completeStarshipArguments(prefix) {
|
|
11
|
-
const normalized = prefix.trim().toLowerCase();
|
|
12
|
-
const matches = STARSHIP_SUBCOMMANDS.filter((item) => item.value.startsWith(normalized));
|
|
13
|
-
return matches.length > 0 ? [...matches] : null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// src/config.ts
|
|
17
|
-
import { randomUUID } from "node:crypto";
|
|
18
|
-
import {
|
|
19
|
-
existsSync,
|
|
20
|
-
lstatSync,
|
|
21
|
-
mkdirSync,
|
|
22
|
-
readFileSync,
|
|
23
|
-
renameSync,
|
|
24
|
-
rmSync,
|
|
25
|
-
writeFileSync
|
|
26
|
-
} from "node:fs";
|
|
27
|
-
import { createRequire } from "node:module";
|
|
28
|
-
import { dirname, join } from "node:path";
|
|
29
|
-
|
|
30
|
-
// src/format/style.ts
|
|
31
|
-
function isFillChunk(chunk) {
|
|
32
|
-
return "type" in chunk && chunk.type === "fill";
|
|
33
|
-
}
|
|
34
|
-
var NAMED_COLORS = /* @__PURE__ */ new Set([
|
|
35
|
-
"black",
|
|
36
|
-
"red",
|
|
37
|
-
"green",
|
|
38
|
-
"yellow",
|
|
39
|
-
"blue",
|
|
40
|
-
"purple",
|
|
41
|
-
"cyan",
|
|
42
|
-
"white",
|
|
43
|
-
"bright-black",
|
|
44
|
-
"bright-red",
|
|
45
|
-
"bright-green",
|
|
46
|
-
"bright-yellow",
|
|
47
|
-
"bright-blue",
|
|
48
|
-
"bright-purple",
|
|
49
|
-
"bright-cyan",
|
|
50
|
-
"bright-white"
|
|
51
|
-
]);
|
|
52
|
-
var FOREGROUND_CODES = {
|
|
53
|
-
black: 30,
|
|
54
|
-
red: 31,
|
|
55
|
-
green: 32,
|
|
56
|
-
yellow: 33,
|
|
57
|
-
blue: 34,
|
|
58
|
-
purple: 35,
|
|
59
|
-
cyan: 36,
|
|
60
|
-
white: 37,
|
|
61
|
-
"bright-black": 90,
|
|
62
|
-
"bright-red": 91,
|
|
63
|
-
"bright-green": 92,
|
|
64
|
-
"bright-yellow": 93,
|
|
65
|
-
"bright-blue": 94,
|
|
66
|
-
"bright-purple": 95,
|
|
67
|
-
"bright-cyan": 96,
|
|
68
|
-
"bright-white": 97
|
|
69
|
-
};
|
|
70
|
-
function isValidStyle(styleString, palette = {}) {
|
|
71
|
-
return parseStyleResult(styleString, palette).valid;
|
|
72
|
-
}
|
|
73
|
-
function parseStyleResult(styleString, palette = {}) {
|
|
74
|
-
const tokens = styleString.split(/\s+/u).filter(Boolean).map(normalizeStyleToken);
|
|
75
|
-
if (tokens.some(({ token, foreground }) => foreground && token === "none")) {
|
|
76
|
-
return { valid: true, style: void 0 };
|
|
77
|
-
}
|
|
78
|
-
const style = {};
|
|
79
|
-
for (const { token, foreground } of tokens) {
|
|
80
|
-
if (applyModifier(style, token)) continue;
|
|
81
|
-
if (token === "prev_fg" || token === "prev_bg") {
|
|
82
|
-
const source = token === "prev_fg" ? "foreground" : "background";
|
|
83
|
-
if (foreground) style.foregroundPrevious = source;
|
|
84
|
-
else style.backgroundPrevious = source;
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
const color = parseColor(token, palette);
|
|
88
|
-
if (!foreground && !color) {
|
|
89
|
-
delete style.background;
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (!color) return { valid: false, style: void 0 };
|
|
93
|
-
if (foreground) style.foreground = color;
|
|
94
|
-
else style.background = color;
|
|
95
|
-
}
|
|
96
|
-
return { valid: true, style };
|
|
97
|
-
}
|
|
98
|
-
function parseStyle(styleString, palette = {}) {
|
|
99
|
-
return parseStyleResult(styleString, palette).style;
|
|
100
|
-
}
|
|
101
|
-
function normalizeStyleToken(rawToken) {
|
|
102
|
-
let token = rawToken.toLowerCase();
|
|
103
|
-
if (token.startsWith("fg:")) {
|
|
104
|
-
return { token: token.replace(/^(?:fg:)+/u, ""), foreground: true };
|
|
105
|
-
}
|
|
106
|
-
if (token.startsWith("bg:")) {
|
|
107
|
-
token = token.replace(/^(?:bg:)+/u, "");
|
|
108
|
-
return { token, foreground: false };
|
|
109
|
-
}
|
|
110
|
-
return { token, foreground: true };
|
|
111
|
-
}
|
|
112
|
-
function applyModifier(style, token) {
|
|
113
|
-
switch (token) {
|
|
114
|
-
case "bold":
|
|
115
|
-
style.bold = true;
|
|
116
|
-
return true;
|
|
117
|
-
case "italic":
|
|
118
|
-
style.italic = true;
|
|
119
|
-
return true;
|
|
120
|
-
case "underline":
|
|
121
|
-
style.underline = true;
|
|
122
|
-
return true;
|
|
123
|
-
case "dimmed":
|
|
124
|
-
style.dimmed = true;
|
|
125
|
-
return true;
|
|
126
|
-
case "inverted":
|
|
127
|
-
style.inverted = true;
|
|
128
|
-
return true;
|
|
129
|
-
case "blink":
|
|
130
|
-
style.blink = true;
|
|
131
|
-
return true;
|
|
132
|
-
case "hidden":
|
|
133
|
-
style.hidden = true;
|
|
134
|
-
return true;
|
|
135
|
-
case "strikethrough":
|
|
136
|
-
style.strikethrough = true;
|
|
137
|
-
return true;
|
|
138
|
-
default:
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function parseColor(token, palette = {}) {
|
|
143
|
-
const paletteValue = Object.hasOwn(palette, token) ? palette[token] : void 0;
|
|
144
|
-
if (paletteValue !== void 0) return parseColor(paletteValue.toLowerCase(), {});
|
|
145
|
-
if (NAMED_COLORS.has(token)) {
|
|
146
|
-
return { kind: "named", name: token };
|
|
147
|
-
}
|
|
148
|
-
if (/^\d{1,3}$/u.test(token)) {
|
|
149
|
-
const value = Number(token);
|
|
150
|
-
return value <= 255 ? { kind: "fixed", value } : void 0;
|
|
151
|
-
}
|
|
152
|
-
const rgb = /^#([0-9a-f]{6})$/iu.exec(token);
|
|
153
|
-
if (!rgb?.[1]) return void 0;
|
|
154
|
-
return {
|
|
155
|
-
kind: "rgb",
|
|
156
|
-
red: Number.parseInt(rgb[1].slice(0, 2), 16),
|
|
157
|
-
green: Number.parseInt(rgb[1].slice(2, 4), 16),
|
|
158
|
-
blue: Number.parseInt(rgb[1].slice(4, 6), 16)
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function renderChunksToAnsi(chunks) {
|
|
162
|
-
const runs = [];
|
|
163
|
-
let previous;
|
|
164
|
-
for (const chunk of chunks) {
|
|
165
|
-
if (isFillChunk(chunk)) continue;
|
|
166
|
-
const style = resolveStyle(chunk.style, previous);
|
|
167
|
-
const last = runs.at(-1);
|
|
168
|
-
if (chunk.text && last && stylesEqual(last.style, style)) last.text += chunk.text;
|
|
169
|
-
else if (chunk.text) runs.push({ text: chunk.text, style });
|
|
170
|
-
previous = style;
|
|
171
|
-
}
|
|
172
|
-
return runs.map(({ text, style }) => {
|
|
173
|
-
const codes = ansiCodes(style);
|
|
174
|
-
return codes.length > 0 ? `\x1B[${codes.join(";")}m${text}\x1B[0m` : text;
|
|
175
|
-
}).join("");
|
|
176
|
-
}
|
|
177
|
-
function stylesEqual(left, right) {
|
|
178
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
179
|
-
}
|
|
180
|
-
function resolveStyle(style, previous) {
|
|
181
|
-
if (!style) return {};
|
|
182
|
-
const { foregroundPrevious, backgroundPrevious, ...resolved } = style;
|
|
183
|
-
return {
|
|
184
|
-
...resolved,
|
|
185
|
-
foreground: resolveColor(style.foreground, foregroundPrevious, previous),
|
|
186
|
-
background: resolveColor(style.background, backgroundPrevious, previous)
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
function resolveColor(fallback, source, previous) {
|
|
190
|
-
if (!source || !previous) return fallback;
|
|
191
|
-
return source === "foreground" ? previous.foreground : previous.background;
|
|
192
|
-
}
|
|
193
|
-
function ansiCodes(style) {
|
|
194
|
-
const codes = [];
|
|
195
|
-
if (style.foreground) codes.push(...colorCodes(style.foreground, false));
|
|
196
|
-
if (style.background) codes.push(...colorCodes(style.background, true));
|
|
197
|
-
if (style.bold) codes.push("1");
|
|
198
|
-
if (style.dimmed) codes.push("2");
|
|
199
|
-
if (style.italic) codes.push("3");
|
|
200
|
-
if (style.underline) codes.push("4");
|
|
201
|
-
if (style.blink) codes.push("5");
|
|
202
|
-
if (style.inverted) codes.push("7");
|
|
203
|
-
if (style.hidden) codes.push("8");
|
|
204
|
-
if (style.strikethrough) codes.push("9");
|
|
205
|
-
return codes;
|
|
206
|
-
}
|
|
207
|
-
function colorCodes(color, background) {
|
|
208
|
-
if (color.kind === "named") {
|
|
209
|
-
const foreground = FOREGROUND_CODES[color.name];
|
|
210
|
-
return [`${background ? foreground + 10 : foreground}`];
|
|
211
|
-
}
|
|
212
|
-
if (color.kind === "fixed") return [background ? "48" : "38", "5", `${color.value}`];
|
|
213
|
-
return [background ? "48" : "38", "2", `${color.red}`, `${color.green}`, `${color.blue}`];
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// src/format/formatter.ts
|
|
217
|
-
var FormatSyntaxError = class extends Error {
|
|
218
|
-
offset;
|
|
219
|
-
constructor(message, offset) {
|
|
220
|
-
super(`${message} at offset ${offset}`);
|
|
221
|
-
this.name = "FormatSyntaxError";
|
|
222
|
-
this.offset = offset;
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
var FUNCTIONAL = /* @__PURE__ */ new Set(["[", "]", "(", ")", "\\", "$"]);
|
|
226
|
-
function parseFormat(format) {
|
|
227
|
-
const parser = new FormatParser(format);
|
|
228
|
-
const nodes = parser.parseNodes();
|
|
229
|
-
if (!parser.done()) throw new FormatSyntaxError("Unexpected character", parser.offset());
|
|
230
|
-
return nodes;
|
|
231
|
-
}
|
|
232
|
-
var FormatParser = class {
|
|
233
|
-
constructor(input) {
|
|
234
|
-
this.input = input;
|
|
235
|
-
}
|
|
236
|
-
input;
|
|
237
|
-
index = 0;
|
|
238
|
-
offset() {
|
|
239
|
-
return this.index;
|
|
240
|
-
}
|
|
241
|
-
done() {
|
|
242
|
-
return this.index === this.input.length;
|
|
243
|
-
}
|
|
244
|
-
parseNodes(end) {
|
|
245
|
-
const nodes = [];
|
|
246
|
-
let text = "";
|
|
247
|
-
const flushText = () => {
|
|
248
|
-
if (!text) return;
|
|
249
|
-
nodes.push({ type: "text", value: text });
|
|
250
|
-
text = "";
|
|
251
|
-
};
|
|
252
|
-
while (!this.done()) {
|
|
253
|
-
const current = this.input[this.index];
|
|
254
|
-
if (current === end) {
|
|
255
|
-
flushText();
|
|
256
|
-
this.index += 1;
|
|
257
|
-
return nodes;
|
|
258
|
-
}
|
|
259
|
-
if (current === "\\") {
|
|
260
|
-
const escaped = this.input[this.index + 1];
|
|
261
|
-
if (!escaped || !FUNCTIONAL.has(escaped)) {
|
|
262
|
-
throw new FormatSyntaxError("Invalid escape", this.index);
|
|
263
|
-
}
|
|
264
|
-
text += escaped;
|
|
265
|
-
this.index += 2;
|
|
266
|
-
continue;
|
|
267
|
-
}
|
|
268
|
-
if (current === "$") {
|
|
269
|
-
flushText();
|
|
270
|
-
nodes.push({ type: "variable", name: this.parseVariable() });
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
if (current === "[") {
|
|
274
|
-
flushText();
|
|
275
|
-
this.index += 1;
|
|
276
|
-
const children = this.parseNodes("]");
|
|
277
|
-
if (this.input[this.index] !== "(") {
|
|
278
|
-
throw new FormatSyntaxError("Text group requires a style", this.index);
|
|
279
|
-
}
|
|
280
|
-
this.index += 1;
|
|
281
|
-
nodes.push({ type: "group", children, style: this.parseStyleNodes() });
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
if (current === "(") {
|
|
285
|
-
flushText();
|
|
286
|
-
this.index += 1;
|
|
287
|
-
nodes.push({ type: "conditional", children: this.parseNodes(")") });
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
if (current === "]" || current === ")") {
|
|
291
|
-
throw new FormatSyntaxError(`Unexpected ${current}`, this.index);
|
|
292
|
-
}
|
|
293
|
-
text += current;
|
|
294
|
-
this.index += 1;
|
|
295
|
-
}
|
|
296
|
-
if (end) throw new FormatSyntaxError(`Missing ${end}`, this.index);
|
|
297
|
-
flushText();
|
|
298
|
-
return nodes;
|
|
299
|
-
}
|
|
300
|
-
parseVariable() {
|
|
301
|
-
const start = this.index;
|
|
302
|
-
this.index += 1;
|
|
303
|
-
if (this.input[this.index] === "{") {
|
|
304
|
-
this.index += 1;
|
|
305
|
-
const nameStart = this.index;
|
|
306
|
-
while (!this.done() && this.input[this.index] !== "}") {
|
|
307
|
-
const current = this.input[this.index];
|
|
308
|
-
if (!current || FUNCTIONAL.has(current) || current === "{") {
|
|
309
|
-
throw new FormatSyntaxError("Invalid scoped variable", this.index);
|
|
310
|
-
}
|
|
311
|
-
this.index += 1;
|
|
312
|
-
}
|
|
313
|
-
if (this.done() || this.index === nameStart) {
|
|
314
|
-
throw new FormatSyntaxError("Unclosed scoped variable", start);
|
|
315
|
-
}
|
|
316
|
-
const name = this.input.slice(nameStart, this.index);
|
|
317
|
-
this.index += 1;
|
|
318
|
-
return name;
|
|
319
|
-
}
|
|
320
|
-
const match = /^[A-Za-z_][A-Za-z0-9_]*/u.exec(this.input.slice(this.index));
|
|
321
|
-
if (!match) throw new FormatSyntaxError("Invalid variable", start);
|
|
322
|
-
this.index += match[0].length;
|
|
323
|
-
return match[0];
|
|
324
|
-
}
|
|
325
|
-
parseStyleNodes() {
|
|
326
|
-
const nodes = [];
|
|
327
|
-
let text = "";
|
|
328
|
-
const flushText = () => {
|
|
329
|
-
if (!text) return;
|
|
330
|
-
nodes.push({ type: "text", value: text });
|
|
331
|
-
text = "";
|
|
332
|
-
};
|
|
333
|
-
while (!this.done()) {
|
|
334
|
-
const current = this.input[this.index];
|
|
335
|
-
if (current === ")") {
|
|
336
|
-
flushText();
|
|
337
|
-
this.index += 1;
|
|
338
|
-
return nodes;
|
|
339
|
-
}
|
|
340
|
-
if (current === "$") {
|
|
341
|
-
flushText();
|
|
342
|
-
nodes.push({ type: "variable", name: this.parseVariable() });
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
if (current === "(" || current === "[" || current === "]" || current === "\\") {
|
|
346
|
-
throw new FormatSyntaxError("Invalid style character", this.index);
|
|
347
|
-
}
|
|
348
|
-
text += current;
|
|
349
|
-
this.index += 1;
|
|
350
|
-
}
|
|
351
|
-
throw new FormatSyntaxError("Missing )", this.index);
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
function formatVariables(nodes) {
|
|
355
|
-
const variables = /* @__PURE__ */ new Set();
|
|
356
|
-
for (const node of nodes) {
|
|
357
|
-
if (node.type === "variable") variables.add(node.name);
|
|
358
|
-
else if (node.type === "group" || node.type === "conditional") {
|
|
359
|
-
for (const variable of formatVariables(node.children)) variables.add(variable);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return variables;
|
|
363
|
-
}
|
|
364
|
-
function styleVariables(nodes) {
|
|
365
|
-
const variables = /* @__PURE__ */ new Set();
|
|
366
|
-
for (const node of nodes) {
|
|
367
|
-
if (node.type === "group") {
|
|
368
|
-
for (const part of node.style) {
|
|
369
|
-
if (part.type === "variable") variables.add(part.name);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
if (node.type === "group" || node.type === "conditional") {
|
|
373
|
-
for (const variable of styleVariables(node.children)) variables.add(variable);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return variables;
|
|
377
|
-
}
|
|
378
|
-
function renderFormat(nodes, options) {
|
|
379
|
-
return renderNodes(nodes, options, void 0);
|
|
380
|
-
}
|
|
381
|
-
function renderNodes(nodes, options, inheritedStyle) {
|
|
382
|
-
const chunks = [];
|
|
383
|
-
for (const node of nodes) {
|
|
384
|
-
switch (node.type) {
|
|
385
|
-
case "text":
|
|
386
|
-
chunks.push({ text: node.value, style: inheritedStyle });
|
|
387
|
-
break;
|
|
388
|
-
case "variable":
|
|
389
|
-
chunks.push(...chunksForValue(ownValue(options.variables, node.name), inheritedStyle));
|
|
390
|
-
break;
|
|
391
|
-
case "conditional":
|
|
392
|
-
if (conditionalVisible(node.children, options.variables)) {
|
|
393
|
-
chunks.push(...renderNodes(node.children, options, inheritedStyle));
|
|
394
|
-
}
|
|
395
|
-
break;
|
|
396
|
-
case "group": {
|
|
397
|
-
const styleString = node.style.map(
|
|
398
|
-
(part) => part.type === "text" ? part.value : ownValue(options.styleVariables, part.name) ?? ""
|
|
399
|
-
).join("");
|
|
400
|
-
const style = parseStyle(styleString, options.palette);
|
|
401
|
-
const rendered = renderNodes(node.children, options, style);
|
|
402
|
-
if (node.children.length === 0) chunks.push({ text: "", style });
|
|
403
|
-
else chunks.push(...rendered);
|
|
404
|
-
break;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return chunks;
|
|
409
|
-
}
|
|
410
|
-
function ownValue(record, key) {
|
|
411
|
-
return record && Object.hasOwn(record, key) ? record[key] : void 0;
|
|
412
|
-
}
|
|
413
|
-
function chunksForValue(value, inheritedStyle) {
|
|
414
|
-
if (value === void 0) return [];
|
|
415
|
-
if (typeof value === "string") return [{ text: value, style: inheritedStyle }];
|
|
416
|
-
return value.map(
|
|
417
|
-
(chunk) => isFillChunk(chunk) ? {
|
|
418
|
-
type: "fill",
|
|
419
|
-
pattern: chunk.pattern.map((part) => ({
|
|
420
|
-
...part,
|
|
421
|
-
style: part.style ?? inheritedStyle
|
|
422
|
-
}))
|
|
423
|
-
} : { ...chunk, style: chunk.style ?? inheritedStyle }
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
function conditionalVisible(nodes, variables) {
|
|
427
|
-
for (const variable of formatVariables(nodes)) {
|
|
428
|
-
const value = ownValue(variables, variable);
|
|
429
|
-
if (typeof value === "string" ? value.length > 0 : value?.some((chunk) => isFillChunk(chunk) || chunk.text.length > 0)) {
|
|
430
|
-
return true;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
return false;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// src/modules/types.ts
|
|
437
|
-
function defineModule(definition) {
|
|
438
|
-
return definition;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// src/modules/activity.ts
|
|
442
|
-
var activityModule = defineModule({
|
|
443
|
-
name: "activity",
|
|
444
|
-
variables: ["symbol", "state", "tool", "count", "text"],
|
|
445
|
-
defaults: {
|
|
446
|
-
format: "[ $text ]($style)",
|
|
447
|
-
symbol: "\u2699",
|
|
448
|
-
style: "bold yellow",
|
|
449
|
-
disabled: false
|
|
450
|
-
},
|
|
451
|
-
values: ({ runtime, symbol }) => {
|
|
452
|
-
const active = [...runtime.activeTools.entries()];
|
|
453
|
-
if (active.length > 0) {
|
|
454
|
-
const [tool = "tool", count2 = 1] = active[0] ?? [];
|
|
455
|
-
const suffix = count2 > 1 ? `\xD7${count2}` : "";
|
|
456
|
-
const more = active.length > 1 ? `+${active.length - 1}` : "";
|
|
457
|
-
return {
|
|
458
|
-
state: "active",
|
|
459
|
-
tool,
|
|
460
|
-
count: `${count2}`,
|
|
461
|
-
text: `${symbol} ${tool}${suffix}${more}`
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
if (runtime.isStreaming) {
|
|
465
|
-
return { state: "thinking", tool: "", count: "0", text: `${symbol} thinking` };
|
|
466
|
-
}
|
|
467
|
-
if (runtime.lastCompletedTool) {
|
|
468
|
-
return {
|
|
469
|
-
state: "completed",
|
|
470
|
-
tool: runtime.lastCompletedTool,
|
|
471
|
-
count: "0",
|
|
472
|
-
text: `${symbol} completed ${runtime.lastCompletedTool}`
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
return { state: "idle", tool: "", count: "0", text: `${symbol} idle` };
|
|
476
|
-
}
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
// src/modules/brand.ts
|
|
480
|
-
var brandModule = defineModule({
|
|
481
|
-
name: "brand",
|
|
482
|
-
variables: ["symbol"],
|
|
483
|
-
defaults: {
|
|
484
|
-
format: "[ $symbol ]($style)",
|
|
485
|
-
symbol: "\u03C0",
|
|
486
|
-
style: "bold white",
|
|
487
|
-
disabled: false
|
|
488
|
-
},
|
|
489
|
-
values: () => ({})
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
// src/modules/helpers.ts
|
|
493
|
-
function formatCount(value) {
|
|
494
|
-
if (value < 1e3) return `${value}`;
|
|
495
|
-
if (value < 1e6) return `${(value / 1e3).toFixed(value < 1e4 ? 1 : 0)}k`;
|
|
496
|
-
return `${(value / 1e6).toFixed(1)}m`;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
// src/modules/cache.ts
|
|
500
|
-
var cacheModule = defineModule({
|
|
501
|
-
name: "cache",
|
|
502
|
-
variables: ["symbol", "rate", "read", "write"],
|
|
503
|
-
defaults: {
|
|
504
|
-
format: "[$symbol (CH$rate )]($style)",
|
|
505
|
-
symbol: "\u{1F4E6}",
|
|
506
|
-
style: "bold green",
|
|
507
|
-
disabled: true
|
|
508
|
-
},
|
|
509
|
-
values: ({ runtime }) => {
|
|
510
|
-
const { cacheRead, cacheWrite, latestCacheHitRate } = runtime.tokenTotals;
|
|
511
|
-
if (cacheRead === 0 && cacheWrite === 0) return void 0;
|
|
512
|
-
const rate = latestCacheHitRate === void 0 ? "" : `${latestCacheHitRate.toFixed(1)}%`;
|
|
513
|
-
return {
|
|
514
|
-
rate,
|
|
515
|
-
read: cacheRead > 0 ? formatCount(cacheRead) : "",
|
|
516
|
-
write: cacheWrite > 0 ? formatCount(cacheWrite) : ""
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
});
|
|
520
|
-
|
|
521
|
-
// src/modules/workspace-helpers.ts
|
|
522
|
-
function workspaceModuleValues(name, context) {
|
|
523
|
-
const values = context.runtime.workspace?.modules[name];
|
|
524
|
-
if (!values) return void 0;
|
|
525
|
-
return { ...values };
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
// src/modules/cloud.ts
|
|
529
|
-
function cloudModule(definition) {
|
|
530
|
-
return defineModule({
|
|
531
|
-
name: definition.name,
|
|
532
|
-
variables: ["symbol", ...definition.variables],
|
|
533
|
-
defaults: {
|
|
534
|
-
format: definition.format,
|
|
535
|
-
symbol: definition.symbol,
|
|
536
|
-
style: definition.style,
|
|
537
|
-
disabled: false
|
|
538
|
-
},
|
|
539
|
-
options: definition.options,
|
|
540
|
-
values: (context) => workspaceModuleValues(definition.name, context)
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
var awsModule = cloudModule({
|
|
544
|
-
name: "aws",
|
|
545
|
-
variables: ["profile", "region"],
|
|
546
|
-
format: "on [$symbol($profile )(\\($region\\) )]($style)",
|
|
547
|
-
symbol: "\u2601\uFE0F ",
|
|
548
|
-
style: "bold yellow",
|
|
549
|
-
options: {
|
|
550
|
-
profile_aliases: { kind: "string-map", default: {} },
|
|
551
|
-
region_aliases: { kind: "string-map", default: {} }
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
var gcloudModule = cloudModule({
|
|
555
|
-
name: "gcloud",
|
|
556
|
-
variables: ["active", "account", "domain", "project", "region"],
|
|
557
|
-
format: "on [$symbol$project]($style) ",
|
|
558
|
-
symbol: "\u2601\uFE0F ",
|
|
559
|
-
style: "bold blue",
|
|
560
|
-
options: {
|
|
561
|
-
project_aliases: { kind: "string-map", default: {} },
|
|
562
|
-
region_aliases: { kind: "string-map", default: {} }
|
|
563
|
-
}
|
|
564
|
-
});
|
|
565
|
-
var azureModule = cloudModule({
|
|
566
|
-
name: "azure",
|
|
567
|
-
variables: ["subscription", "username"],
|
|
568
|
-
format: "on [$symbol$subscription]($style) ",
|
|
569
|
-
symbol: "\u{F0805} ",
|
|
570
|
-
style: "blue bold",
|
|
571
|
-
options: {
|
|
572
|
-
subscription_aliases: { kind: "string-map", default: {} },
|
|
573
|
-
show_username: { kind: "boolean", default: false }
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
var openstackModule = cloudModule({
|
|
577
|
-
name: "openstack",
|
|
578
|
-
variables: ["cloud", "project"],
|
|
579
|
-
format: "on [$symbol$cloud( \\($project\\))]($style) ",
|
|
580
|
-
symbol: "\u2601\uFE0F ",
|
|
581
|
-
style: "bold yellow",
|
|
582
|
-
options: {
|
|
583
|
-
cloud_aliases: { kind: "string-map", default: {} },
|
|
584
|
-
project_aliases: { kind: "string-map", default: {} }
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
var cloudModules = [awsModule, gcloudModule, azureModule, openstackModule];
|
|
588
|
-
|
|
589
|
-
// src/modules/display.ts
|
|
590
|
-
function resolveDisplayStyle(display, value) {
|
|
591
|
-
if (value === null || value === void 0 || !Number.isFinite(value)) return void 0;
|
|
592
|
-
let selected;
|
|
593
|
-
for (const entry of display) {
|
|
594
|
-
if (entry.threshold > value) continue;
|
|
595
|
-
if (!selected || entry.threshold >= selected.threshold) selected = entry;
|
|
596
|
-
}
|
|
597
|
-
return selected && !selected.hidden ? selected.style : void 0;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
// src/modules/context.ts
|
|
601
|
-
var contextModule = defineModule({
|
|
602
|
-
name: "context",
|
|
603
|
-
variables: ["symbol", "percentage", "tokens", "window"],
|
|
604
|
-
defaults: {
|
|
605
|
-
format: "[$symbol ctx $percentage ]($style)",
|
|
606
|
-
symbol: "\u{1FA9F}",
|
|
607
|
-
style: "none",
|
|
608
|
-
disabled: false
|
|
609
|
-
},
|
|
610
|
-
displayDefaults: [
|
|
611
|
-
{ threshold: 0, style: "bold green", hidden: true },
|
|
612
|
-
{ threshold: 30, style: "bold green", hidden: false },
|
|
613
|
-
{ threshold: 60, style: "bold yellow", hidden: false },
|
|
614
|
-
{ threshold: 80, style: "bold red", hidden: false }
|
|
615
|
-
],
|
|
616
|
-
styleVariables: ["style"],
|
|
617
|
-
resolveStyleVariables: ({ runtime, display }) => {
|
|
618
|
-
const style = resolveDisplayStyle(display, runtime.contextUsage?.percent);
|
|
619
|
-
return style === void 0 ? void 0 : { style };
|
|
620
|
-
},
|
|
621
|
-
values: ({ runtime }) => {
|
|
622
|
-
const percent = runtime.contextUsage?.percent;
|
|
623
|
-
return {
|
|
624
|
-
percentage: percent === null || percent === void 0 ? "?" : `${percent.toFixed(1)}%`,
|
|
625
|
-
tokens: formatCount(runtime.contextUsage?.tokens ?? 0),
|
|
626
|
-
window: formatCount(runtime.contextUsage?.contextWindow ?? 0)
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
|
|
631
|
-
// src/modules/cost.ts
|
|
632
|
-
var costModule = defineModule({
|
|
633
|
-
name: "cost",
|
|
634
|
-
variables: ["symbol", "cost", "subscription"],
|
|
635
|
-
defaults: {
|
|
636
|
-
format: "[ $symbol \\$$cost( $subscription) ]($style)",
|
|
637
|
-
symbol: "\u{1F4B8}",
|
|
638
|
-
style: "none",
|
|
639
|
-
disabled: false
|
|
640
|
-
},
|
|
641
|
-
displayDefaults: [
|
|
642
|
-
{ threshold: 0, style: "bold green", hidden: true },
|
|
643
|
-
{ threshold: 1, style: "bold yellow", hidden: false },
|
|
644
|
-
{ threshold: 5, style: "bold red", hidden: false }
|
|
645
|
-
],
|
|
646
|
-
styleVariables: ["style"],
|
|
647
|
-
resolveStyleVariables: ({ runtime, display }) => {
|
|
648
|
-
const style = resolveDisplayStyle(display, runtime.tokenTotals.cost);
|
|
649
|
-
return style === void 0 ? void 0 : { style };
|
|
650
|
-
},
|
|
651
|
-
values: ({ runtime }) => ({
|
|
652
|
-
cost: formatCost(runtime.tokenTotals.cost),
|
|
653
|
-
subscription: runtime.usingSubscription ? "(sub)" : ""
|
|
654
|
-
})
|
|
655
|
-
});
|
|
656
|
-
function formatCost(value) {
|
|
657
|
-
return value.toFixed(value >= 1 ? 2 : 3);
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
// src/modules/deployment.ts
|
|
661
|
-
var directDetection = {
|
|
662
|
-
detect_files: { kind: "string-array", default: [] },
|
|
663
|
-
detect_extensions: { kind: "string-array", default: [] },
|
|
664
|
-
detect_folders: { kind: "string-array", default: [] }
|
|
665
|
-
};
|
|
666
|
-
var dockerContextModule = defineModule({
|
|
667
|
-
name: "docker_context",
|
|
668
|
-
variables: ["symbol", "context"],
|
|
669
|
-
defaults: {
|
|
670
|
-
format: "via [$symbol$context]($style) ",
|
|
671
|
-
symbol: "\uF308 ",
|
|
672
|
-
style: "blue bold",
|
|
673
|
-
disabled: false
|
|
674
|
-
},
|
|
675
|
-
options: {
|
|
676
|
-
...directDetection,
|
|
677
|
-
only_with_files: { kind: "boolean", default: false }
|
|
678
|
-
},
|
|
679
|
-
values: (context) => workspaceModuleValues("docker_context", context)
|
|
680
|
-
});
|
|
681
|
-
var kubernetesModule = defineModule({
|
|
682
|
-
name: "kubernetes",
|
|
683
|
-
variables: ["symbol", "context", "namespace", "cluster", "user"],
|
|
684
|
-
defaults: {
|
|
685
|
-
format: "on [$symbol$context( \\($namespace\\))]($style) ",
|
|
686
|
-
symbol: "\u2638 ",
|
|
687
|
-
style: "cyan bold",
|
|
688
|
-
disabled: false
|
|
689
|
-
},
|
|
690
|
-
options: {
|
|
691
|
-
context_aliases: { kind: "string-map", default: {} },
|
|
692
|
-
namespace_aliases: { kind: "string-map", default: {} },
|
|
693
|
-
cluster_aliases: { kind: "string-map", default: {} },
|
|
694
|
-
user_aliases: { kind: "string-map", default: {} },
|
|
695
|
-
max_config_files: { kind: "integer", default: 8, minimum: 1, maximum: 32 }
|
|
696
|
-
},
|
|
697
|
-
values: (context) => workspaceModuleValues("kubernetes", context)
|
|
698
|
-
});
|
|
699
|
-
var terraformModule = defineModule({
|
|
700
|
-
name: "terraform",
|
|
701
|
-
variables: ["symbol", "workspace", "version"],
|
|
702
|
-
defaults: {
|
|
703
|
-
format: "via [$symbol$workspace]($style) ",
|
|
704
|
-
symbol: "\u{1F4A0} ",
|
|
705
|
-
style: "bold 105",
|
|
706
|
-
disabled: false
|
|
707
|
-
},
|
|
708
|
-
options: {
|
|
709
|
-
...directDetection,
|
|
710
|
-
version_format: { kind: "string", default: "v$raw" }
|
|
711
|
-
},
|
|
712
|
-
values: (context) => workspaceModuleValues("terraform", context)
|
|
713
|
-
});
|
|
714
|
-
var deploymentModules = [dockerContextModule, kubernetesModule, terraformModule];
|
|
715
|
-
|
|
716
|
-
// src/modules/truncation.ts
|
|
717
|
-
import { sep } from "node:path";
|
|
718
|
-
var graphemeSegmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
719
|
-
function graphemes(value) {
|
|
720
|
-
return [...graphemeSegmenter.segment(value)].map(({ segment }) => segment);
|
|
721
|
-
}
|
|
722
|
-
function firstGrapheme(value) {
|
|
723
|
-
return graphemes(value)[0] ?? "";
|
|
724
|
-
}
|
|
725
|
-
function truncateLeadingGraphemes(value, length, symbol) {
|
|
726
|
-
if (length <= 0) return value;
|
|
727
|
-
const parts = graphemes(value);
|
|
728
|
-
if (parts.length <= length) return value;
|
|
729
|
-
return `${parts.slice(0, length).join("")}${firstGrapheme(symbol)}`;
|
|
730
|
-
}
|
|
731
|
-
function toSlashPath(value) {
|
|
732
|
-
return sep === "\\" ? value.replaceAll("\\", "/") : value;
|
|
733
|
-
}
|
|
734
|
-
function truncatePathComponents(value, length) {
|
|
735
|
-
if (length <= 0) return { value, truncated: false };
|
|
736
|
-
const normalized = toSlashPath(value);
|
|
737
|
-
const components = normalized.split("/").filter((component) => component.length > 0);
|
|
738
|
-
if (components.length <= length) return { value: normalized, truncated: false };
|
|
739
|
-
return { value: components.slice(-length).join("/"), truncated: true };
|
|
740
|
-
}
|
|
741
|
-
function useNativePathSeparator(value) {
|
|
742
|
-
return sep === "/" ? value : value.replaceAll("/", sep);
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
// src/modules/development.ts
|
|
746
|
-
function developmentModule(definition) {
|
|
747
|
-
return defineModule({
|
|
748
|
-
name: definition.name,
|
|
749
|
-
variables: ["symbol", ...definition.variables],
|
|
750
|
-
defaults: {
|
|
751
|
-
format: definition.format,
|
|
752
|
-
symbol: definition.symbol,
|
|
753
|
-
style: definition.style,
|
|
754
|
-
disabled: false
|
|
755
|
-
},
|
|
756
|
-
options: definition.options,
|
|
757
|
-
values: (context) => workspaceModuleValues(definition.name, context)
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
var directDetection2 = {
|
|
761
|
-
detect_files: { kind: "string-array", default: [] },
|
|
762
|
-
detect_extensions: { kind: "string-array", default: [] },
|
|
763
|
-
detect_folders: { kind: "string-array", default: [] }
|
|
764
|
-
};
|
|
765
|
-
var miseModule = developmentModule({
|
|
766
|
-
name: "mise",
|
|
767
|
-
variables: ["health"],
|
|
768
|
-
format: "via [$symbol$health]($style) ",
|
|
769
|
-
symbol: "mise ",
|
|
770
|
-
style: "bold purple",
|
|
771
|
-
options: directDetection2
|
|
772
|
-
});
|
|
773
|
-
var direnvModule = developmentModule({
|
|
774
|
-
name: "direnv",
|
|
775
|
-
variables: ["rc_path", "allowed", "loaded"],
|
|
776
|
-
format: "[$symbol$loaded]($style) ",
|
|
777
|
-
symbol: "direnv ",
|
|
778
|
-
style: "bold bright-yellow",
|
|
779
|
-
options: directDetection2
|
|
780
|
-
});
|
|
781
|
-
var condaModule = defineModule({
|
|
782
|
-
name: "conda",
|
|
783
|
-
variables: ["symbol", "environment"],
|
|
784
|
-
defaults: {
|
|
785
|
-
format: "via [$symbol$environment]($style) ",
|
|
786
|
-
symbol: "\u{1F152} ",
|
|
787
|
-
style: "green bold",
|
|
788
|
-
disabled: false
|
|
789
|
-
},
|
|
790
|
-
options: {
|
|
791
|
-
ignore_base: { kind: "boolean", default: true },
|
|
792
|
-
truncation_length: { kind: "integer", default: 1, minimum: 0, maximum: 1e6 }
|
|
793
|
-
},
|
|
794
|
-
values: (context) => {
|
|
795
|
-
const values = workspaceModuleValues("conda", context);
|
|
796
|
-
const environment = values?.environment;
|
|
797
|
-
if (!environment) return void 0;
|
|
798
|
-
const length = typeof context.options.truncation_length === "number" ? context.options.truncation_length : 1;
|
|
799
|
-
return {
|
|
800
|
-
environment: truncatePathComponents(environment, length).value
|
|
801
|
-
};
|
|
802
|
-
}
|
|
803
|
-
});
|
|
804
|
-
var pixiModule = developmentModule({
|
|
805
|
-
name: "pixi",
|
|
806
|
-
variables: ["version", "environment", "project_name"],
|
|
807
|
-
format: "via [$symbol$environment]($style) ",
|
|
808
|
-
symbol: "\u{1F9DA} ",
|
|
809
|
-
style: "yellow bold",
|
|
810
|
-
options: {
|
|
811
|
-
...directDetection2,
|
|
812
|
-
version_format: { kind: "string", default: "v$raw" },
|
|
813
|
-
show_default_environment: { kind: "boolean", default: false }
|
|
814
|
-
}
|
|
815
|
-
});
|
|
816
|
-
var nixShellModule = developmentModule({
|
|
817
|
-
name: "nix_shell",
|
|
818
|
-
variables: ["state", "name", "level"],
|
|
819
|
-
format: "via [$symbol$state( \\($name\\))]($style) ",
|
|
820
|
-
symbol: "\uF313 ",
|
|
821
|
-
style: "bold blue"
|
|
822
|
-
});
|
|
823
|
-
var guixShellModule = developmentModule({
|
|
824
|
-
name: "guix_shell",
|
|
825
|
-
variables: ["state"],
|
|
826
|
-
format: "via [$symbol]($style) ",
|
|
827
|
-
symbol: "\u{1F403} ",
|
|
828
|
-
style: "yellow bold"
|
|
829
|
-
});
|
|
830
|
-
var developmentModules = [
|
|
831
|
-
miseModule,
|
|
832
|
-
direnvModule,
|
|
833
|
-
condaModule,
|
|
834
|
-
pixiModule,
|
|
835
|
-
nixShellModule,
|
|
836
|
-
guixShellModule
|
|
837
|
-
];
|
|
838
|
-
|
|
839
|
-
// src/modules/directory.ts
|
|
840
|
-
import { basename, isAbsolute, relative, sep as sep2 } from "node:path";
|
|
841
|
-
|
|
842
|
-
// src/modules/terminal.ts
|
|
843
|
-
function sanitizeTerminalText(value) {
|
|
844
|
-
let result = "";
|
|
845
|
-
for (let index = 0; index < value.length; ) {
|
|
846
|
-
const codePoint = value.codePointAt(index) ?? 0;
|
|
847
|
-
const character = String.fromCodePoint(codePoint);
|
|
848
|
-
if (codePoint === 27 || codePoint === 155 || codePoint === 157) {
|
|
849
|
-
index = skipTerminalEscape(value, index, codePoint);
|
|
850
|
-
continue;
|
|
851
|
-
}
|
|
852
|
-
if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159 || codePoint === 8232 || codePoint === 8233) {
|
|
853
|
-
if (codePoint === 9 || codePoint === 10 || codePoint === 13 || codePoint === 133 || codePoint === 8232 || codePoint === 8233) {
|
|
854
|
-
result += " ";
|
|
855
|
-
}
|
|
856
|
-
index += character.length;
|
|
857
|
-
continue;
|
|
858
|
-
}
|
|
859
|
-
result += character;
|
|
860
|
-
index += character.length;
|
|
861
|
-
}
|
|
862
|
-
return result;
|
|
863
|
-
}
|
|
864
|
-
function skipTerminalEscape(value, start, codePoint) {
|
|
865
|
-
let index = start + 1;
|
|
866
|
-
const next = value.charCodeAt(index);
|
|
867
|
-
const isOsc = codePoint === 157 || codePoint === 27 && next === 93;
|
|
868
|
-
if (isOsc) {
|
|
869
|
-
if (codePoint === 27) index += 1;
|
|
870
|
-
while (index < value.length) {
|
|
871
|
-
const current = value.charCodeAt(index);
|
|
872
|
-
if (current === 7 || current === 156) return index + 1;
|
|
873
|
-
if (current === 27 && value.charCodeAt(index + 1) === 92) return index + 2;
|
|
874
|
-
index += 1;
|
|
875
|
-
}
|
|
876
|
-
return index;
|
|
877
|
-
}
|
|
878
|
-
const isCsi = codePoint === 155 || codePoint === 27 && next === 91;
|
|
879
|
-
if (isCsi) {
|
|
880
|
-
if (codePoint === 27) index += 1;
|
|
881
|
-
while (index < value.length) {
|
|
882
|
-
const current = value.charCodeAt(index);
|
|
883
|
-
index += 1;
|
|
884
|
-
if (current >= 64 && current <= 126) break;
|
|
885
|
-
}
|
|
886
|
-
return index;
|
|
887
|
-
}
|
|
888
|
-
return Math.min(value.length, start + (codePoint === 27 ? 2 : 1));
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
// src/modules/directory.ts
|
|
892
|
-
var directoryModule = defineModule({
|
|
893
|
-
name: "directory",
|
|
894
|
-
variables: ["symbol", "path", "full_path"],
|
|
895
|
-
defaults: {
|
|
896
|
-
format: "[ $symbol $path ]($style)",
|
|
897
|
-
symbol: "\u{1F4C1}",
|
|
898
|
-
style: "cyan bold",
|
|
899
|
-
disabled: false
|
|
900
|
-
},
|
|
901
|
-
options: {
|
|
902
|
-
truncation_length: { kind: "integer", default: 3, minimum: 0, maximum: 1e6 },
|
|
903
|
-
truncate_to_repo: { kind: "boolean", default: true },
|
|
904
|
-
fish_style_pwd_dir_length: { kind: "integer", default: 0, minimum: 0, maximum: 1e3 },
|
|
905
|
-
truncation_symbol: { kind: "string", default: "" },
|
|
906
|
-
home_symbol: { kind: "string", default: "~" },
|
|
907
|
-
use_os_path_sep: { kind: "boolean", default: true },
|
|
908
|
-
substitutions: { kind: "string-map", default: {} }
|
|
909
|
-
},
|
|
910
|
-
values: ({ runtime, options }) => {
|
|
911
|
-
const fullPath = runtime.cwd;
|
|
912
|
-
const home = runtime.homeDir;
|
|
913
|
-
const repoRoot = runtime.gitRoot;
|
|
914
|
-
const homeSymbol = stringOption(options, "home_symbol", "~");
|
|
915
|
-
const truncateToRepo = booleanOption(options, "truncate_to_repo", true);
|
|
916
|
-
const substitutions = mapOption(options, "substitutions");
|
|
917
|
-
const homeContracted = contractPath(fullPath, home, homeSymbol);
|
|
918
|
-
const repoContracted = truncateToRepo && repoRoot && (!home || !samePath(repoRoot, home)) ? contractRepositoryPath(fullPath, repoRoot) : void 0;
|
|
919
|
-
let path = sanitizeTerminalText(repoContracted ?? homeContracted);
|
|
920
|
-
let truncated = repoContracted !== void 0;
|
|
921
|
-
for (const [from, to] of Object.entries(substitutions)) {
|
|
922
|
-
if (from) path = path.replaceAll(from, to);
|
|
923
|
-
}
|
|
924
|
-
const componentResult = truncatePathComponents(
|
|
925
|
-
path,
|
|
926
|
-
numberOption(options, "truncation_length", 3)
|
|
927
|
-
);
|
|
928
|
-
path = componentResult.value;
|
|
929
|
-
truncated ||= componentResult.truncated;
|
|
930
|
-
if (truncated) {
|
|
931
|
-
const fishLength = numberOption(options, "fish_style_pwd_dir_length", 0);
|
|
932
|
-
if (fishLength > 0 && Object.keys(substitutions).length === 0) {
|
|
933
|
-
path = `${fishPrefix(homeContracted, path, fishLength)}${path}`;
|
|
934
|
-
} else {
|
|
935
|
-
path = `${stringOption(options, "truncation_symbol", "")}${path}`;
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
if (booleanOption(options, "use_os_path_sep", true)) path = useNativePathSeparator(path);
|
|
939
|
-
const fallback = basename(fullPath) || fullPath;
|
|
940
|
-
return {
|
|
941
|
-
path: sanitizeTerminalText(path || fallback),
|
|
942
|
-
full_path: sanitizeTerminalText(fullPath)
|
|
943
|
-
};
|
|
944
|
-
}
|
|
945
|
-
});
|
|
946
|
-
function contractPath(path, root, replacement) {
|
|
947
|
-
if (!root) return toSlashPath(path);
|
|
948
|
-
const child = relativeWithin(path, root);
|
|
949
|
-
if (child === void 0) return toSlashPath(path);
|
|
950
|
-
return child ? `${replacement}/${child}` : replacement;
|
|
951
|
-
}
|
|
952
|
-
function contractRepositoryPath(path, root) {
|
|
953
|
-
const child = relativeWithin(path, root);
|
|
954
|
-
if (child === void 0) return void 0;
|
|
955
|
-
const name = basename(root) || toSlashPath(root);
|
|
956
|
-
return child ? `${name}/${child}` : name;
|
|
957
|
-
}
|
|
958
|
-
function relativeWithin(path, root) {
|
|
959
|
-
const child = relative(root, path);
|
|
960
|
-
if (child === "") return "";
|
|
961
|
-
if (child === ".." || child.startsWith(`..${sep2}`) || isAbsolute(child)) return void 0;
|
|
962
|
-
return toSlashPath(child);
|
|
963
|
-
}
|
|
964
|
-
function samePath(left, right) {
|
|
965
|
-
return relative(left, right) === "";
|
|
966
|
-
}
|
|
967
|
-
function fishPrefix(source, displayed, length) {
|
|
968
|
-
const prefix = source.endsWith(displayed) ? source.slice(0, -displayed.length) : "";
|
|
969
|
-
if (!prefix) return "";
|
|
970
|
-
return prefix.split("/").map((component) => abbreviateComponent(component, length)).join("/");
|
|
971
|
-
}
|
|
972
|
-
function abbreviateComponent(component, length) {
|
|
973
|
-
if (!component) return "";
|
|
974
|
-
const parts = graphemes(component);
|
|
975
|
-
if (parts.length <= length) return component;
|
|
976
|
-
return component.startsWith(".") ? parts.slice(0, length + 1).join("") : parts.slice(0, length).join("");
|
|
977
|
-
}
|
|
978
|
-
function numberOption(options, name, fallback) {
|
|
979
|
-
const value = options[name];
|
|
980
|
-
return typeof value === "number" ? value : fallback;
|
|
981
|
-
}
|
|
982
|
-
function stringOption(options, name, fallback) {
|
|
983
|
-
const value = options[name];
|
|
984
|
-
return typeof value === "string" ? value : fallback;
|
|
985
|
-
}
|
|
986
|
-
function booleanOption(options, name, fallback) {
|
|
987
|
-
const value = options[name];
|
|
988
|
-
return typeof value === "boolean" ? value : fallback;
|
|
989
|
-
}
|
|
990
|
-
function mapOption(options, name) {
|
|
991
|
-
const value = options[name];
|
|
992
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
// src/modules/execution.ts
|
|
996
|
-
var osModule = defineModule({
|
|
997
|
-
name: "os",
|
|
998
|
-
variables: ["symbol", "type", "name", "version", "edition", "codename"],
|
|
999
|
-
defaults: {
|
|
1000
|
-
format: "[$symbol($name )]($style)",
|
|
1001
|
-
symbol: "",
|
|
1002
|
-
style: "bold white",
|
|
1003
|
-
disabled: true
|
|
1004
|
-
},
|
|
1005
|
-
options: {
|
|
1006
|
-
symbols: {
|
|
1007
|
-
kind: "string-map",
|
|
1008
|
-
default: { linux: "\u{1F427} ", macos: "\u{1F34E} ", windows: "\uE62A ", wsl: "\uF31A " }
|
|
1009
|
-
}
|
|
1010
|
-
},
|
|
1011
|
-
values: (context) => workspaceModuleValues("os", context)
|
|
1012
|
-
});
|
|
1013
|
-
var containerModule = defineModule({
|
|
1014
|
-
name: "container",
|
|
1015
|
-
variables: ["symbol", "name", "type"],
|
|
1016
|
-
defaults: {
|
|
1017
|
-
format: "[$symbol$name]($style) ",
|
|
1018
|
-
symbol: "\u2B22 ",
|
|
1019
|
-
style: "bold red dimmed",
|
|
1020
|
-
disabled: false
|
|
1021
|
-
},
|
|
1022
|
-
values: (context) => workspaceModuleValues("container", context)
|
|
1023
|
-
});
|
|
1024
|
-
var hostnameModule = defineModule({
|
|
1025
|
-
name: "hostname",
|
|
1026
|
-
variables: ["symbol", "hostname", "ssh_symbol"],
|
|
1027
|
-
defaults: {
|
|
1028
|
-
format: "[$ssh_symbol$hostname]($style) in ",
|
|
1029
|
-
symbol: "",
|
|
1030
|
-
style: "bold dimmed green",
|
|
1031
|
-
disabled: false
|
|
1032
|
-
},
|
|
1033
|
-
options: {
|
|
1034
|
-
ssh_only: { kind: "boolean", default: true },
|
|
1035
|
-
trim_at: { kind: "string", default: "." },
|
|
1036
|
-
aliases: { kind: "string-map", default: {} }
|
|
1037
|
-
},
|
|
1038
|
-
values: (context) => workspaceModuleValues("hostname", context)
|
|
1039
|
-
});
|
|
1040
|
-
var usernameModule = defineModule({
|
|
1041
|
-
name: "username",
|
|
1042
|
-
variables: ["symbol", "user"],
|
|
1043
|
-
defaults: {
|
|
1044
|
-
format: "[$user]($style) in ",
|
|
1045
|
-
symbol: "",
|
|
1046
|
-
style: "none",
|
|
1047
|
-
disabled: false
|
|
1048
|
-
},
|
|
1049
|
-
styleDefaults: {
|
|
1050
|
-
style_user: "yellow bold",
|
|
1051
|
-
style_root: "red bold"
|
|
1052
|
-
},
|
|
1053
|
-
styleVariables: ["style"],
|
|
1054
|
-
resolveStyleVariables: ({ runtime, styles }) => ({
|
|
1055
|
-
style: runtime.workspace?.styleSelectors?.username === "root" ? styles.style_root ?? "" : styles.style_user ?? ""
|
|
1056
|
-
}),
|
|
1057
|
-
options: {
|
|
1058
|
-
show_always: { kind: "boolean", default: false },
|
|
1059
|
-
aliases: { kind: "string-map", default: {} },
|
|
1060
|
-
detect_env_vars: { kind: "string-array", default: [] }
|
|
1061
|
-
},
|
|
1062
|
-
values: (context) => workspaceModuleValues("username", context)
|
|
1063
|
-
});
|
|
1064
|
-
var executionModules = [
|
|
1065
|
-
osModule,
|
|
1066
|
-
containerModule,
|
|
1067
|
-
hostnameModule,
|
|
1068
|
-
usernameModule
|
|
1069
|
-
];
|
|
1070
|
-
|
|
1071
|
-
// src/modules/extension-status.ts
|
|
1072
|
-
var extensionStatusModule = defineModule({
|
|
1073
|
-
name: "extension_status",
|
|
1074
|
-
variables: ["symbol", "statuses", "count"],
|
|
1075
|
-
defaults: {
|
|
1076
|
-
format: "[$statuses]($style)",
|
|
1077
|
-
symbol: "",
|
|
1078
|
-
style: "dimmed white",
|
|
1079
|
-
disabled: false
|
|
1080
|
-
},
|
|
1081
|
-
values: ({ runtime, extensionStatus }) => {
|
|
1082
|
-
const statuses = [...runtime.extensionStatuses.entries()].filter(([key, value]) => key !== "starship" && value.trim()).map(([key, value]) => formatExtensionStatus(key, value, extensionStatus.icons)).slice(0, extensionStatus.maxStatuses);
|
|
1083
|
-
if (statuses.length === 0) return void 0;
|
|
1084
|
-
return {
|
|
1085
|
-
statuses: statuses.join(extensionStatus.separator),
|
|
1086
|
-
count: `${statuses.length}`
|
|
1087
|
-
};
|
|
1088
|
-
}
|
|
1089
|
-
});
|
|
1090
|
-
function formatExtensionStatus(key, value, configuredIcons) {
|
|
1091
|
-
const status = splitExtensionStatusIcon(stripExtensionStatusPrefix(key, value));
|
|
1092
|
-
const icon = extensionStatusIcon(key, status.icon, configuredIcons);
|
|
1093
|
-
const text = simplifyExtensionStatusText(status.text);
|
|
1094
|
-
return icon ? `${icon} ${text}` : text;
|
|
1095
|
-
}
|
|
1096
|
-
function extensionStatusIcon(key, leadingIcon, configuredIcons) {
|
|
1097
|
-
if (Object.hasOwn(configuredIcons, key)) return configuredIcons[key] ?? "";
|
|
1098
|
-
const namespaceIcon = configuredNamespaceIcon(key, configuredIcons);
|
|
1099
|
-
if (namespaceIcon !== void 0) return namespaceIcon;
|
|
1100
|
-
const fallbackIcon = Object.hasOwn(configuredIcons, "fallback") ? configuredIcons.fallback : void 0;
|
|
1101
|
-
return leadingIcon ?? fallbackIcon ?? "\u{1F50C}";
|
|
1102
|
-
}
|
|
1103
|
-
function configuredNamespaceIcon(key, configuredIcons) {
|
|
1104
|
-
let match;
|
|
1105
|
-
for (const [selector, icon] of Object.entries(configuredIcons)) {
|
|
1106
|
-
if (!selector.endsWith(":*")) continue;
|
|
1107
|
-
const base = selector.slice(0, -2);
|
|
1108
|
-
if (!base || !key.startsWith(`${base}:`)) continue;
|
|
1109
|
-
if (!match || base.length > match.baseLength) match = { baseLength: base.length, icon };
|
|
1110
|
-
}
|
|
1111
|
-
return match?.icon;
|
|
1112
|
-
}
|
|
1113
|
-
function splitExtensionStatusIcon(value) {
|
|
1114
|
-
const trimmed = value.trim();
|
|
1115
|
-
const [first, ...rest] = trimmed.split(/\s+/u);
|
|
1116
|
-
if (first && isEmojiOnlyToken(first)) return { icon: first, text: rest.join(" ") };
|
|
1117
|
-
return { text: trimmed };
|
|
1118
|
-
}
|
|
1119
|
-
function isEmojiOnlyToken(value) {
|
|
1120
|
-
return /^(?=.*(?:\p{Extended_Pictographic}|\p{Regional_Indicator}|[0-9#*]\ufe0f?\u20e3))(?:\p{Extended_Pictographic}|\p{Emoji_Modifier}|\p{Regional_Indicator}|\u200d|\ufe0f|[0-9#*]\ufe0f?\u20e3)+$/u.test(
|
|
1121
|
-
value
|
|
1122
|
-
);
|
|
1123
|
-
}
|
|
1124
|
-
function stripExtensionStatusPrefix(key, value) {
|
|
1125
|
-
return value.trim().replace(new RegExp(`^${escapeRegExp(key)}\\s*:\\s*`, "iu"), "");
|
|
1126
|
-
}
|
|
1127
|
-
function simplifyExtensionStatusText(value) {
|
|
1128
|
-
return value.trim().replace(/\bready\b/giu, "\u2713").replace(/\bmissing\b/giu, "\u2717").replace(/,\s*/g, " ").replace(/\s+\([^)]*\)\s*$/u, "").replace(/\s+/gu, " ");
|
|
1129
|
-
}
|
|
1130
|
-
function escapeRegExp(value) {
|
|
1131
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
// src/modules/fill.ts
|
|
1135
|
-
var fillModule = defineModule({
|
|
1136
|
-
name: "fill",
|
|
1137
|
-
variables: ["symbol"],
|
|
1138
|
-
defaults: {
|
|
1139
|
-
format: "[$symbol]($style)",
|
|
1140
|
-
symbol: " ",
|
|
1141
|
-
style: "bold black",
|
|
1142
|
-
disabled: false
|
|
1143
|
-
},
|
|
1144
|
-
layout: "fill",
|
|
1145
|
-
values: () => ({})
|
|
1146
|
-
});
|
|
1147
|
-
|
|
1148
|
-
// src/modules/git/branch.ts
|
|
1149
|
-
var gitBranchModule = defineModule({
|
|
1150
|
-
name: "git_branch",
|
|
1151
|
-
variables: ["symbol", "branch", "remote_name", "remote_branch"],
|
|
1152
|
-
defaults: {
|
|
1153
|
-
format: "[ $symbol $branch ]($style)",
|
|
1154
|
-
symbol: "\u{1F33F}",
|
|
1155
|
-
style: "bold purple",
|
|
1156
|
-
disabled: false
|
|
1157
|
-
},
|
|
1158
|
-
options: {
|
|
1159
|
-
// Starship uses i64::MAX as its effective no-truncation default. Zero is the
|
|
1160
|
-
// equivalent stable TOML representation in pi-starship's bounded integer schema.
|
|
1161
|
-
truncation_length: { kind: "integer", default: 0, minimum: 0, maximum: 1e6 },
|
|
1162
|
-
truncation_symbol: { kind: "string", default: "\u2026" }
|
|
1163
|
-
},
|
|
1164
|
-
values: ({ runtime, options }) => {
|
|
1165
|
-
const branch = runtime.gitBranchDetails;
|
|
1166
|
-
const name = branch?.name ?? runtime.gitBranch;
|
|
1167
|
-
if (!name) return void 0;
|
|
1168
|
-
const length = typeof options.truncation_length === "number" ? options.truncation_length : 0;
|
|
1169
|
-
const symbol = typeof options.truncation_symbol === "string" ? options.truncation_symbol : "\u2026";
|
|
1170
|
-
return {
|
|
1171
|
-
branch: truncateLeadingGraphemes(name, length, symbol),
|
|
1172
|
-
remote_name: truncateLeadingGraphemes(branch?.remoteName ?? "", length, symbol),
|
|
1173
|
-
remote_branch: truncateLeadingGraphemes(branch?.remoteBranch ?? "", length, symbol)
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
});
|
|
1177
|
-
|
|
1178
|
-
// src/modules/git/commit.ts
|
|
1179
|
-
var DEFAULT_HASH_LENGTH = 7;
|
|
1180
|
-
var gitCommitModule = defineModule({
|
|
1181
|
-
name: "git_commit",
|
|
1182
|
-
variables: ["symbol", "hash", "tag"],
|
|
1183
|
-
defaults: {
|
|
1184
|
-
format: "[ ($hash) ]($style)",
|
|
1185
|
-
symbol: "",
|
|
1186
|
-
style: "green bold",
|
|
1187
|
-
disabled: false
|
|
1188
|
-
},
|
|
1189
|
-
options: {
|
|
1190
|
-
commit_hash_length: { kind: "integer", default: DEFAULT_HASH_LENGTH, minimum: 0, maximum: 64 }
|
|
1191
|
-
},
|
|
1192
|
-
values: ({ runtime, options }) => {
|
|
1193
|
-
const commit = runtime.gitCommit;
|
|
1194
|
-
if (!commit) return void 0;
|
|
1195
|
-
const hashLength = typeof options.commit_hash_length === "number" ? options.commit_hash_length : DEFAULT_HASH_LENGTH;
|
|
1196
|
-
return {
|
|
1197
|
-
hash: commit.hash.slice(0, hashLength),
|
|
1198
|
-
tag: commit.tag ? ` \u{1F3F7} ${commit.tag}` : ""
|
|
1199
|
-
};
|
|
1200
|
-
}
|
|
1201
|
-
});
|
|
1202
|
-
|
|
1203
|
-
// src/modules/git/metrics.ts
|
|
1204
|
-
var gitMetricsModule = defineModule({
|
|
1205
|
-
name: "git_metrics",
|
|
1206
|
-
variables: ["symbol", "added", "deleted"],
|
|
1207
|
-
defaults: {
|
|
1208
|
-
format: "([+$added]($added_style) )([-$deleted]($deleted_style) )",
|
|
1209
|
-
symbol: "",
|
|
1210
|
-
style: "none",
|
|
1211
|
-
disabled: true
|
|
1212
|
-
},
|
|
1213
|
-
styleDefaults: {
|
|
1214
|
-
added_style: "bold green",
|
|
1215
|
-
deleted_style: "bold red"
|
|
1216
|
-
},
|
|
1217
|
-
styleVariables: ["added_style", "deleted_style"],
|
|
1218
|
-
resolveStyleVariables: ({ styles }) => styles,
|
|
1219
|
-
values: ({ runtime }) => {
|
|
1220
|
-
const metrics = runtime.gitMetrics;
|
|
1221
|
-
if (!metrics || metrics.added === 0 && metrics.deleted === 0) return void 0;
|
|
1222
|
-
return {
|
|
1223
|
-
added: metrics.added > 0 ? metrics.added.toString() : "",
|
|
1224
|
-
deleted: metrics.deleted > 0 ? metrics.deleted.toString() : ""
|
|
1225
|
-
};
|
|
1226
|
-
}
|
|
1227
|
-
});
|
|
1228
|
-
|
|
1229
|
-
// src/modules/git/state.ts
|
|
1230
|
-
var gitStateModule = defineModule({
|
|
1231
|
-
name: "git_state",
|
|
1232
|
-
variables: ["symbol", "state", "progress_current", "progress_total"],
|
|
1233
|
-
defaults: {
|
|
1234
|
-
format: "[ ($state( $progress_current/$progress_total)) ]($style)",
|
|
1235
|
-
symbol: "",
|
|
1236
|
-
style: "bold yellow",
|
|
1237
|
-
disabled: false
|
|
1238
|
-
},
|
|
1239
|
-
values: ({ runtime }) => {
|
|
1240
|
-
const state = runtime.gitState;
|
|
1241
|
-
if (!state) return void 0;
|
|
1242
|
-
return {
|
|
1243
|
-
state: state.state,
|
|
1244
|
-
progress_current: state.progressCurrent?.toString() ?? "",
|
|
1245
|
-
progress_total: state.progressTotal?.toString() ?? ""
|
|
1246
|
-
};
|
|
1247
|
-
}
|
|
1248
|
-
});
|
|
1249
|
-
|
|
1250
|
-
// src/modules/git/status.ts
|
|
1251
|
-
var gitStatusModule = defineModule({
|
|
1252
|
-
name: "git_status",
|
|
1253
|
-
variables: [
|
|
1254
|
-
"symbol",
|
|
1255
|
-
"all_status",
|
|
1256
|
-
"ahead_behind",
|
|
1257
|
-
"ahead",
|
|
1258
|
-
"behind",
|
|
1259
|
-
"up_to_date",
|
|
1260
|
-
"diverged",
|
|
1261
|
-
"conflicted",
|
|
1262
|
-
"stashed",
|
|
1263
|
-
"deleted",
|
|
1264
|
-
"renamed",
|
|
1265
|
-
"modified",
|
|
1266
|
-
"typechanged",
|
|
1267
|
-
"staged",
|
|
1268
|
-
"untracked",
|
|
1269
|
-
"worktree_added",
|
|
1270
|
-
"worktree_deleted",
|
|
1271
|
-
"worktree_modified",
|
|
1272
|
-
"worktree_typechanged",
|
|
1273
|
-
"index_added",
|
|
1274
|
-
"index_deleted",
|
|
1275
|
-
"index_modified",
|
|
1276
|
-
"index_typechanged"
|
|
1277
|
-
],
|
|
1278
|
-
defaults: {
|
|
1279
|
-
format: "[$all_status( $ahead_behind) ]($style)",
|
|
1280
|
-
symbol: "",
|
|
1281
|
-
style: "red bold",
|
|
1282
|
-
disabled: false
|
|
1283
|
-
},
|
|
1284
|
-
values: ({ runtime }) => {
|
|
1285
|
-
if (!runtime.gitBranch || !runtime.gitStatus) return void 0;
|
|
1286
|
-
const status = runtime.gitStatus;
|
|
1287
|
-
const ahead = count("\u21E1", status.ahead);
|
|
1288
|
-
const behind = count("\u21E3", status.behind);
|
|
1289
|
-
const diverged = status.ahead > 0 && status.behind > 0 ? `\u21D5\u21E1${formatCount(status.ahead)}\u21E3${formatCount(status.behind)}` : "";
|
|
1290
|
-
const values = {
|
|
1291
|
-
ahead,
|
|
1292
|
-
behind,
|
|
1293
|
-
up_to_date: "",
|
|
1294
|
-
diverged,
|
|
1295
|
-
ahead_behind: diverged || ahead || behind,
|
|
1296
|
-
conflicted: count("=", status.conflicted),
|
|
1297
|
-
stashed: count("$", status.stashed),
|
|
1298
|
-
deleted: count("\u2718", status.deleted),
|
|
1299
|
-
renamed: count("\xBB", status.renamed),
|
|
1300
|
-
modified: count("!", status.modified),
|
|
1301
|
-
typechanged: count("T", status.typechanged),
|
|
1302
|
-
staged: count("+", status.staged),
|
|
1303
|
-
untracked: count("?", status.untracked),
|
|
1304
|
-
worktree_added: count("A", status.worktreeAdded),
|
|
1305
|
-
worktree_deleted: count("D", status.worktreeDeleted),
|
|
1306
|
-
worktree_modified: count("M", status.worktreeModified),
|
|
1307
|
-
worktree_typechanged: count("T", status.worktreeTypechanged),
|
|
1308
|
-
index_added: count("A", status.indexAdded),
|
|
1309
|
-
index_deleted: count("D", status.indexDeleted),
|
|
1310
|
-
index_modified: count("M", status.indexModified),
|
|
1311
|
-
index_typechanged: count("T", status.indexTypechanged)
|
|
1312
|
-
};
|
|
1313
|
-
const allStatus = [
|
|
1314
|
-
values.conflicted,
|
|
1315
|
-
values.stashed,
|
|
1316
|
-
values.deleted,
|
|
1317
|
-
values.renamed,
|
|
1318
|
-
values.modified,
|
|
1319
|
-
values.typechanged,
|
|
1320
|
-
values.staged,
|
|
1321
|
-
values.untracked
|
|
1322
|
-
].filter(Boolean).join(" ");
|
|
1323
|
-
return allStatus || values.ahead_behind ? { ...values, all_status: allStatus } : void 0;
|
|
1324
|
-
}
|
|
1325
|
-
});
|
|
1326
|
-
function count(symbol, value) {
|
|
1327
|
-
return value > 0 ? `${symbol}${formatCount(value)}` : "";
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
// src/modules/git/worktree.ts
|
|
1331
|
-
var gitWorktreeModule = defineModule({
|
|
1332
|
-
name: "git_worktree",
|
|
1333
|
-
variables: ["symbol", "name", "path"],
|
|
1334
|
-
defaults: {
|
|
1335
|
-
format: "[ $symbol $name ]($style)",
|
|
1336
|
-
symbol: "\u{1F333}",
|
|
1337
|
-
style: "cyan bold",
|
|
1338
|
-
disabled: false
|
|
1339
|
-
},
|
|
1340
|
-
values: ({ runtime }) => runtime.gitWorktree ? { name: runtime.gitWorktree.name, path: runtime.gitWorktree.path } : void 0
|
|
1341
|
-
});
|
|
1342
|
-
|
|
1343
|
-
// src/modules/github-pr.ts
|
|
1344
|
-
var githubPrModule = defineModule({
|
|
1345
|
-
name: "github_pr",
|
|
1346
|
-
variables: ["symbol", "number", "link", "state", "checks", "review", "status"],
|
|
1347
|
-
defaults: {
|
|
1348
|
-
format: "[ $symbol$link( \xB7 $status) ]($style)",
|
|
1349
|
-
symbol: "PR ",
|
|
1350
|
-
style: "bold blue",
|
|
1351
|
-
disabled: false
|
|
1352
|
-
},
|
|
1353
|
-
values: ({ runtime }) => {
|
|
1354
|
-
const snapshot = runtime.githubPr;
|
|
1355
|
-
if (!snapshot) return void 0;
|
|
1356
|
-
return {
|
|
1357
|
-
number: snapshot.number,
|
|
1358
|
-
link: snapshot.link,
|
|
1359
|
-
state: snapshot.state,
|
|
1360
|
-
checks: snapshot.checks,
|
|
1361
|
-
review: snapshot.review,
|
|
1362
|
-
status: snapshot.status
|
|
1363
|
-
};
|
|
1364
|
-
}
|
|
1365
|
-
});
|
|
1366
|
-
|
|
1367
|
-
// src/modules/languages.ts
|
|
1368
|
-
var detectionOptions = {
|
|
1369
|
-
version_format: { kind: "string", default: "v$raw" },
|
|
1370
|
-
detect_files: { kind: "string-array", default: [], allowNegative: true },
|
|
1371
|
-
detect_extensions: { kind: "string-array", default: [], allowNegative: true },
|
|
1372
|
-
detect_folders: { kind: "string-array", default: [], allowNegative: true }
|
|
1373
|
-
};
|
|
1374
|
-
function languageModule(definition) {
|
|
1375
|
-
return defineModule({
|
|
1376
|
-
name: definition.name,
|
|
1377
|
-
variables: ["symbol", ...definition.variables],
|
|
1378
|
-
defaults: {
|
|
1379
|
-
format: definition.format,
|
|
1380
|
-
symbol: definition.symbol,
|
|
1381
|
-
style: definition.style,
|
|
1382
|
-
disabled: false
|
|
1383
|
-
},
|
|
1384
|
-
options: detectionOptions,
|
|
1385
|
-
values: (context) => workspaceModuleValues(definition.name, context)
|
|
1386
|
-
});
|
|
1387
|
-
}
|
|
1388
|
-
var nodejsModule = languageModule({
|
|
1389
|
-
name: "nodejs",
|
|
1390
|
-
variables: ["version", "engines_version"],
|
|
1391
|
-
format: "via [$symbol($version )]($style)",
|
|
1392
|
-
symbol: "\uE718 ",
|
|
1393
|
-
style: "bold green"
|
|
1394
|
-
});
|
|
1395
|
-
var pythonModule = languageModule({
|
|
1396
|
-
name: "python",
|
|
1397
|
-
variables: ["version", "virtualenv", "pyenv_prefix"],
|
|
1398
|
-
format: "via [$symbol$pyenv_prefix($version )(\\($virtualenv\\) )]($style)",
|
|
1399
|
-
symbol: "\uE235 ",
|
|
1400
|
-
style: "yellow bold"
|
|
1401
|
-
});
|
|
1402
|
-
var rustModule = languageModule({
|
|
1403
|
-
name: "rust",
|
|
1404
|
-
variables: ["version", "numver", "toolchain"],
|
|
1405
|
-
format: "via [$symbol($version )]($style)",
|
|
1406
|
-
symbol: "\uE7A8 ",
|
|
1407
|
-
style: "bold red"
|
|
1408
|
-
});
|
|
1409
|
-
var golangModule = languageModule({
|
|
1410
|
-
name: "golang",
|
|
1411
|
-
variables: ["version", "mod_version"],
|
|
1412
|
-
format: "via [$symbol($version )]($style)",
|
|
1413
|
-
symbol: "\uE627 ",
|
|
1414
|
-
style: "bold cyan"
|
|
1415
|
-
});
|
|
1416
|
-
var bunModule = languageModule({
|
|
1417
|
-
name: "bun",
|
|
1418
|
-
variables: ["version"],
|
|
1419
|
-
format: "via [$symbol($version )]($style)",
|
|
1420
|
-
symbol: "\u{1F35E} ",
|
|
1421
|
-
style: "bold red"
|
|
1422
|
-
});
|
|
1423
|
-
var denoModule = languageModule({
|
|
1424
|
-
name: "deno",
|
|
1425
|
-
variables: ["version"],
|
|
1426
|
-
format: "via [$symbol($version )]($style)",
|
|
1427
|
-
symbol: "\u{1F995} ",
|
|
1428
|
-
style: "green bold"
|
|
1429
|
-
});
|
|
1430
|
-
var languageModules = [
|
|
1431
|
-
nodejsModule,
|
|
1432
|
-
pythonModule,
|
|
1433
|
-
rustModule,
|
|
1434
|
-
golangModule,
|
|
1435
|
-
bunModule,
|
|
1436
|
-
denoModule
|
|
1437
|
-
];
|
|
1438
|
-
|
|
1439
|
-
// src/modules/model.ts
|
|
1440
|
-
var TRUNCATION_DIRECTIONS = ["start", "middle", "end"];
|
|
1441
|
-
var graphemeSegmenter2 = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
1442
|
-
var modelModule = defineModule({
|
|
1443
|
-
name: "model",
|
|
1444
|
-
variables: ["symbol", "model"],
|
|
1445
|
-
defaults: {
|
|
1446
|
-
format: "[$symbol $model ]($style)",
|
|
1447
|
-
symbol: "\u{1F916}",
|
|
1448
|
-
style: "bold blue",
|
|
1449
|
-
disabled: false
|
|
1450
|
-
},
|
|
1451
|
-
options: {
|
|
1452
|
-
truncation_length: { kind: "integer", default: 0, minimum: 0, maximum: 1e3 },
|
|
1453
|
-
truncation_symbol: { kind: "string", default: "\u2026" },
|
|
1454
|
-
truncation_direction: {
|
|
1455
|
-
kind: "string-enum",
|
|
1456
|
-
default: "end",
|
|
1457
|
-
values: TRUNCATION_DIRECTIONS
|
|
1458
|
-
},
|
|
1459
|
-
model_aliases: { kind: "string-map", default: {} }
|
|
1460
|
-
},
|
|
1461
|
-
values: ({ runtime, options }) => {
|
|
1462
|
-
if (!runtime.model) return void 0;
|
|
1463
|
-
const length = typeof options.truncation_length === "number" ? options.truncation_length : 0;
|
|
1464
|
-
const symbol = typeof options.truncation_symbol === "string" ? options.truncation_symbol : "\u2026";
|
|
1465
|
-
const direction = isTruncationDirection(options.truncation_direction) ? options.truncation_direction : "end";
|
|
1466
|
-
const aliases = options.model_aliases;
|
|
1467
|
-
const aliasMap = aliases && typeof aliases === "object" && !Array.isArray(aliases) ? aliases : void 0;
|
|
1468
|
-
const alias = aliasMap && Object.hasOwn(aliasMap, runtime.model.id) ? aliasMap[runtime.model.id] : void 0;
|
|
1469
|
-
return {
|
|
1470
|
-
model: truncateModel(alias ?? shortenModel(runtime.model.id), length, symbol, direction)
|
|
1471
|
-
};
|
|
1472
|
-
}
|
|
1473
|
-
});
|
|
1474
|
-
function truncateModel(model, length, symbol, direction) {
|
|
1475
|
-
const safeModel = sanitizeTerminalText(model);
|
|
1476
|
-
if (length === 0) return safeModel;
|
|
1477
|
-
const graphemes2 = [...graphemeSegmenter2.segment(safeModel)].map(({ segment }) => segment);
|
|
1478
|
-
if (graphemes2.length <= length) return safeModel;
|
|
1479
|
-
const safeSymbol = sanitizeTerminalText(symbol);
|
|
1480
|
-
switch (direction) {
|
|
1481
|
-
case "start":
|
|
1482
|
-
return `${safeSymbol}${graphemes2.slice(-length).join("")}`;
|
|
1483
|
-
case "middle": {
|
|
1484
|
-
const headLength = Math.ceil(length / 2);
|
|
1485
|
-
const tailLength = Math.floor(length / 2);
|
|
1486
|
-
const tail = tailLength > 0 ? graphemes2.slice(-tailLength).join("") : "";
|
|
1487
|
-
return `${graphemes2.slice(0, headLength).join("")}${safeSymbol}${tail}`;
|
|
1488
|
-
}
|
|
1489
|
-
case "end":
|
|
1490
|
-
return `${graphemes2.slice(0, length).join("")}${safeSymbol}`;
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
function isTruncationDirection(value) {
|
|
1494
|
-
return TRUNCATION_DIRECTIONS.includes(value);
|
|
1495
|
-
}
|
|
1496
|
-
function shortenModel(model) {
|
|
1497
|
-
return model.replace(/^claude-/u, "").replace(/^gpt-/u, "gpt ").replace(/-20\d{6}$/u, "").replace(/-latest$/u, "");
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
// src/modules/package.ts
|
|
1501
|
-
var packageModule = defineModule({
|
|
1502
|
-
name: "package",
|
|
1503
|
-
variables: ["symbol", "version", "source"],
|
|
1504
|
-
defaults: {
|
|
1505
|
-
format: "via [$symbol$version]($style) ",
|
|
1506
|
-
symbol: "\u{1F4E6} ",
|
|
1507
|
-
style: "bold 208",
|
|
1508
|
-
disabled: false
|
|
1509
|
-
},
|
|
1510
|
-
options: {
|
|
1511
|
-
version_format: { kind: "string", default: "v$raw" }
|
|
1512
|
-
},
|
|
1513
|
-
values: (context) => workspaceModuleValues("package", context)
|
|
1514
|
-
});
|
|
1515
|
-
|
|
1516
|
-
// src/modules/provider.ts
|
|
1517
|
-
var providerModule = defineModule({
|
|
1518
|
-
name: "provider",
|
|
1519
|
-
variables: ["symbol", "provider"],
|
|
1520
|
-
defaults: {
|
|
1521
|
-
format: "[$symbol $provider ]($style)",
|
|
1522
|
-
symbol: "\u{1F50C}",
|
|
1523
|
-
style: "bold blue",
|
|
1524
|
-
disabled: false
|
|
1525
|
-
},
|
|
1526
|
-
values: ({ runtime }) => runtime.model ? { provider: runtime.model.provider } : void 0
|
|
1527
|
-
});
|
|
1528
|
-
|
|
1529
|
-
// src/modules/thinking.ts
|
|
1530
|
-
var thinkingModule = defineModule({
|
|
1531
|
-
name: "thinking",
|
|
1532
|
-
variables: ["symbol", "level"],
|
|
1533
|
-
defaults: {
|
|
1534
|
-
format: "[$symbol $level ]($style)",
|
|
1535
|
-
symbol: "\u{1F9E0}",
|
|
1536
|
-
style: "bold purple",
|
|
1537
|
-
disabled: false
|
|
1538
|
-
},
|
|
1539
|
-
values: ({ runtime }) => ({ level: runtime.thinkingLevel })
|
|
1540
|
-
});
|
|
1541
|
-
|
|
1542
|
-
// src/modules/time.ts
|
|
1543
|
-
var timeModule = defineModule({
|
|
1544
|
-
name: "time",
|
|
1545
|
-
variables: ["symbol", "time"],
|
|
1546
|
-
defaults: {
|
|
1547
|
-
format: "[$symbol $time ]($style)",
|
|
1548
|
-
symbol: "\u{1F552}",
|
|
1549
|
-
style: "bold yellow",
|
|
1550
|
-
disabled: false
|
|
1551
|
-
},
|
|
1552
|
-
values: ({ runtime }) => ({ time: formatTime(runtime.now) })
|
|
1553
|
-
});
|
|
1554
|
-
function formatTime(now) {
|
|
1555
|
-
return `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}`;
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1558
|
-
// src/modules/tokens.ts
|
|
1559
|
-
var tokensModule = defineModule({
|
|
1560
|
-
name: "tokens",
|
|
1561
|
-
variables: ["symbol", "input", "output", "total"],
|
|
1562
|
-
defaults: {
|
|
1563
|
-
format: "[$symbol \u2191$input \u2193$output ]($style)",
|
|
1564
|
-
symbol: "\u{1F522}",
|
|
1565
|
-
style: "bold cyan",
|
|
1566
|
-
disabled: false
|
|
1567
|
-
},
|
|
1568
|
-
values: ({ runtime }) => ({
|
|
1569
|
-
input: formatCount(runtime.tokenTotals.input),
|
|
1570
|
-
output: formatCount(runtime.tokenTotals.output),
|
|
1571
|
-
total: formatCount(runtime.tokenTotals.input + runtime.tokenTotals.output)
|
|
1572
|
-
})
|
|
1573
|
-
});
|
|
1574
|
-
|
|
1575
|
-
// src/modules/turn.ts
|
|
1576
|
-
var turnModule = defineModule({
|
|
1577
|
-
name: "turn",
|
|
1578
|
-
variables: ["symbol", "count"],
|
|
1579
|
-
defaults: {
|
|
1580
|
-
format: "[$symbol #$count ]($style)",
|
|
1581
|
-
symbol: "\u{1F501}",
|
|
1582
|
-
style: "bold purple",
|
|
1583
|
-
disabled: false
|
|
1584
|
-
},
|
|
1585
|
-
values: ({ runtime }) => ({ count: `${runtime.turnCount}` })
|
|
1586
|
-
});
|
|
1587
|
-
|
|
1588
|
-
// src/modules/catalog.ts
|
|
1589
|
-
var MODULE_IMPLEMENTATIONS = [
|
|
1590
|
-
brandModule,
|
|
1591
|
-
providerModule,
|
|
1592
|
-
modelModule,
|
|
1593
|
-
thinkingModule,
|
|
1594
|
-
directoryModule,
|
|
1595
|
-
gitWorktreeModule,
|
|
1596
|
-
gitBranchModule,
|
|
1597
|
-
githubPrModule,
|
|
1598
|
-
gitCommitModule,
|
|
1599
|
-
gitStateModule,
|
|
1600
|
-
gitMetricsModule,
|
|
1601
|
-
gitStatusModule,
|
|
1602
|
-
packageModule,
|
|
1603
|
-
...languageModules,
|
|
1604
|
-
...developmentModules,
|
|
1605
|
-
...deploymentModules,
|
|
1606
|
-
...cloudModules,
|
|
1607
|
-
...executionModules,
|
|
1608
|
-
activityModule,
|
|
1609
|
-
contextModule,
|
|
1610
|
-
tokensModule,
|
|
1611
|
-
cacheModule,
|
|
1612
|
-
costModule,
|
|
1613
|
-
timeModule,
|
|
1614
|
-
turnModule,
|
|
1615
|
-
fillModule,
|
|
1616
|
-
// Keep arbitrary third-party statuses after the native modules.
|
|
1617
|
-
extensionStatusModule
|
|
1618
|
-
];
|
|
1619
|
-
var MODULE_DESCRIPTIONS = {
|
|
1620
|
-
activity: "Current Pi activity or most recently completed tool.",
|
|
1621
|
-
aws: "Active AWS profile and region.",
|
|
1622
|
-
azure: "Active Azure subscription and optional username.",
|
|
1623
|
-
brand: "pi-starship brand mark.",
|
|
1624
|
-
bun: "Bun version detected in the current workspace.",
|
|
1625
|
-
cache: "Prompt-cache usage and latest cache hit rate.",
|
|
1626
|
-
conda: "Active Conda environment.",
|
|
1627
|
-
container: "Current container or remote development environment.",
|
|
1628
|
-
context: "Current model context-window usage.",
|
|
1629
|
-
cost: "Reported estimated session cost or subscription state.",
|
|
1630
|
-
deno: "Deno version detected in the current workspace.",
|
|
1631
|
-
directory: "Current working directory.",
|
|
1632
|
-
direnv: "Current direnv loading and permission state.",
|
|
1633
|
-
docker_context: "Active Docker context.",
|
|
1634
|
-
extension_status: "Statuses published through Pi's extension-neutral status map.",
|
|
1635
|
-
fill: "Flexible spacing that aligns content within the footer width.",
|
|
1636
|
-
gcloud: "Active Google Cloud project, account, and region.",
|
|
1637
|
-
git_branch: "Current Git branch and upstream identity.",
|
|
1638
|
-
git_commit: "Current Git commit hash or tag.",
|
|
1639
|
-
git_metrics: "Added and deleted lines in the current Git worktree.",
|
|
1640
|
-
git_state: "Current Git operation such as merge, rebase, or cherry-pick.",
|
|
1641
|
-
git_status: "Current Git worktree and index status summary.",
|
|
1642
|
-
git_worktree: "Current linked Git worktree identity.",
|
|
1643
|
-
github_pr: "Current branch's GitHub pull request state, checks, and review.",
|
|
1644
|
-
golang: "Go version detected in the current workspace.",
|
|
1645
|
-
guix_shell: "Current Guix shell state.",
|
|
1646
|
-
hostname: "Current host name, normally shown for remote sessions.",
|
|
1647
|
-
kubernetes: "Active Kubernetes context, namespace, cluster, and user.",
|
|
1648
|
-
mise: "Current mise configuration health.",
|
|
1649
|
-
model: "Current Pi model.",
|
|
1650
|
-
nix_shell: "Current Nix shell state, name, and nesting level.",
|
|
1651
|
-
nodejs: "Node.js version detected in the current workspace.",
|
|
1652
|
-
openstack: "Active OpenStack cloud and project.",
|
|
1653
|
-
os: "Current operating system identity.",
|
|
1654
|
-
package: "Current workspace package name and version.",
|
|
1655
|
-
pixi: "Active Pixi environment and project.",
|
|
1656
|
-
provider: "Current Pi model provider.",
|
|
1657
|
-
python: "Python version, virtual environment, and pyenv state.",
|
|
1658
|
-
rust: "Rust toolchain detected in the current workspace.",
|
|
1659
|
-
terraform: "Active Terraform workspace and version.",
|
|
1660
|
-
thinking: "Current Pi thinking level or streaming state.",
|
|
1661
|
-
time: "Current local time.",
|
|
1662
|
-
tokens: "Session input and output token totals.",
|
|
1663
|
-
turn: "Current user-turn count.",
|
|
1664
|
-
username: "Current user identity when configured to display."
|
|
1665
|
-
};
|
|
1666
|
-
var MODULE_DEFINITIONS = MODULE_IMPLEMENTATIONS.map(
|
|
1667
|
-
(definition) => ({
|
|
1668
|
-
...definition,
|
|
1669
|
-
description: MODULE_DESCRIPTIONS[definition.name]
|
|
1670
|
-
})
|
|
1671
|
-
);
|
|
1672
|
-
var MODULE_NAMES = MODULE_IMPLEMENTATIONS.map(
|
|
1673
|
-
(definition) => definition.name
|
|
1674
|
-
);
|
|
1675
|
-
|
|
1676
|
-
// src/config.ts
|
|
1677
|
-
var CONFIG_FILE_NAME = "pi-starship.toml";
|
|
1678
|
-
var MODULE_CONTENT_VARIABLES = Object.fromEntries(
|
|
1679
|
-
MODULE_DEFINITIONS.map((definition) => [definition.name, definition.variables])
|
|
1680
|
-
);
|
|
1681
|
-
var BUILT_IN_FORMAT_DOCUMENT = String.raw`format = """
|
|
1682
|
-
$brand\
|
|
1683
|
-
$model\
|
|
1684
|
-
$thinking\
|
|
1685
|
-
$directory\
|
|
1686
|
-
$git_branch\
|
|
1687
|
-
$git_status\
|
|
1688
|
-
$activity\
|
|
1689
|
-
$context\
|
|
1690
|
-
$time"""`;
|
|
1691
|
-
var BUILT_IN_FORMAT = "$brand$model$thinking$directory$git_branch$git_status$activity$context$time";
|
|
1692
|
-
var BUILT_IN_MODULES = Object.fromEntries(
|
|
1693
|
-
MODULE_DEFINITIONS.map(({ name, defaults, styleDefaults, displayDefaults, options }) => [
|
|
1694
|
-
name,
|
|
1695
|
-
{
|
|
1696
|
-
...defaults,
|
|
1697
|
-
formatAst: parseFormat(defaults.format),
|
|
1698
|
-
styles: { ...styleDefaults },
|
|
1699
|
-
display: structuredClone(displayDefaults ?? []),
|
|
1700
|
-
options: Object.fromEntries(
|
|
1701
|
-
Object.entries(options ?? {}).map(([key, schema]) => [
|
|
1702
|
-
key,
|
|
1703
|
-
cloneOptionValue(schema.default)
|
|
1704
|
-
])
|
|
1705
|
-
)
|
|
1706
|
-
}
|
|
1707
|
-
])
|
|
1708
|
-
);
|
|
1709
|
-
var BUILT_IN_CONFIG = {
|
|
1710
|
-
format: BUILT_IN_FORMAT,
|
|
1711
|
-
formatAst: parseFormat(BUILT_IN_FORMAT),
|
|
1712
|
-
palette: void 0,
|
|
1713
|
-
palettes: {},
|
|
1714
|
-
modules: BUILT_IN_MODULES,
|
|
1715
|
-
extensionStatus: { separator: " \u2022 ", maxStatuses: 5, icons: {} }
|
|
1716
|
-
};
|
|
1717
|
-
var BUILT_IN_EXAMPLE = `# Native Pi modules with Starship-compatible format and style syntax.
|
|
1718
|
-
${BUILT_IN_FORMAT_DOCUMENT}
|
|
1719
|
-
`;
|
|
1720
|
-
var require2 = createRequire(import.meta.url);
|
|
1721
|
-
var parseTomlImplementation;
|
|
1722
|
-
function parseToml(document) {
|
|
1723
|
-
parseTomlImplementation ??= require2("smol-toml").parse;
|
|
1724
|
-
return parseTomlImplementation(document);
|
|
1725
|
-
}
|
|
1726
|
-
function settingsFilePath(agentDir) {
|
|
1727
|
-
return join(agentDir, CONFIG_FILE_NAME);
|
|
1728
|
-
}
|
|
1729
|
-
function loadStarshipConfig(settingsPath) {
|
|
1730
|
-
let rawDocument;
|
|
1731
|
-
try {
|
|
1732
|
-
rawDocument = readFileSync(settingsPath, "utf8");
|
|
1733
|
-
} catch (error) {
|
|
1734
|
-
if (error.code === "ENOENT" && !existsSync(settingsPath)) {
|
|
1735
|
-
return {
|
|
1736
|
-
config: cloneBuiltInConfig(),
|
|
1737
|
-
source: "built-in",
|
|
1738
|
-
settingsPath,
|
|
1739
|
-
diagnostics: []
|
|
1740
|
-
};
|
|
1741
|
-
}
|
|
1742
|
-
return {
|
|
1743
|
-
config: cloneBuiltInConfig(),
|
|
1744
|
-
source: "built-in",
|
|
1745
|
-
settingsPath,
|
|
1746
|
-
diagnostics: [diagnostic("error", "", `Unable to read settings: ${formatError(error)}`)]
|
|
1747
|
-
};
|
|
1748
|
-
}
|
|
1749
|
-
let parsed;
|
|
1750
|
-
try {
|
|
1751
|
-
parsed = parseToml(rawDocument);
|
|
1752
|
-
} catch (error) {
|
|
1753
|
-
return {
|
|
1754
|
-
config: cloneBuiltInConfig(),
|
|
1755
|
-
source: "built-in",
|
|
1756
|
-
settingsPath,
|
|
1757
|
-
rawDocument,
|
|
1758
|
-
diagnostics: [diagnostic("error", "", `Unable to parse TOML: ${formatError(error)}`)]
|
|
1759
|
-
};
|
|
1760
|
-
}
|
|
1761
|
-
const normalized = normalizeConfig(parsed);
|
|
1762
|
-
return {
|
|
1763
|
-
...normalized,
|
|
1764
|
-
source: "user",
|
|
1765
|
-
settingsPath,
|
|
1766
|
-
rawDocument
|
|
1767
|
-
};
|
|
1768
|
-
}
|
|
1769
|
-
function normalizeConfig(value) {
|
|
1770
|
-
const config = cloneBuiltInConfig();
|
|
1771
|
-
const diagnostics = [];
|
|
1772
|
-
if (!isRecord(value)) {
|
|
1773
|
-
return {
|
|
1774
|
-
config,
|
|
1775
|
-
diagnostics: [diagnostic("error", "", "Settings must contain a TOML table")]
|
|
1776
|
-
};
|
|
1777
|
-
}
|
|
1778
|
-
const knownRoot = /* @__PURE__ */ new Set(["format", "palette", "palettes", ...MODULE_NAMES]);
|
|
1779
|
-
for (const key of Object.keys(value)) {
|
|
1780
|
-
if (!knownRoot.has(key)) diagnostics.push(unknownDiagnostic(key));
|
|
1781
|
-
}
|
|
1782
|
-
if (value.format !== void 0) {
|
|
1783
|
-
if (typeof value.format !== "string") {
|
|
1784
|
-
diagnostics.push(typeDiagnostic("format", "string"));
|
|
1785
|
-
} else {
|
|
1786
|
-
try {
|
|
1787
|
-
config.formatAst = parseFormat(value.format);
|
|
1788
|
-
config.format = value.format;
|
|
1789
|
-
} catch (error) {
|
|
1790
|
-
diagnostics.push(
|
|
1791
|
-
diagnostic("warning", "format", `Invalid format; using built-in: ${formatError(error)}`)
|
|
1792
|
-
);
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
if (value.palettes !== void 0) {
|
|
1797
|
-
if (!isRecord(value.palettes)) {
|
|
1798
|
-
diagnostics.push(typeDiagnostic("palettes", "table"));
|
|
1799
|
-
} else {
|
|
1800
|
-
for (const [paletteName, paletteValue] of Object.entries(value.palettes)) {
|
|
1801
|
-
if (!isRecord(paletteValue)) {
|
|
1802
|
-
diagnostics.push(typeDiagnostic(`palettes.${paletteName}`, "table"));
|
|
1803
|
-
continue;
|
|
1804
|
-
}
|
|
1805
|
-
const palette2 = {};
|
|
1806
|
-
for (const [name, color] of Object.entries(paletteValue)) {
|
|
1807
|
-
if (typeof color !== "string" || !parseColor(color.toLowerCase())) {
|
|
1808
|
-
diagnostics.push(
|
|
1809
|
-
diagnostic(
|
|
1810
|
-
"warning",
|
|
1811
|
-
`palettes.${paletteName}.${name}`,
|
|
1812
|
-
"Palette colors must be named, ANSI 0-255, or #RRGGBB"
|
|
1813
|
-
)
|
|
1814
|
-
);
|
|
1815
|
-
continue;
|
|
1816
|
-
}
|
|
1817
|
-
setOwn(palette2, name, color);
|
|
1818
|
-
}
|
|
1819
|
-
setOwn(config.palettes, paletteName, palette2);
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
if (value.palette !== void 0) {
|
|
1824
|
-
if (typeof value.palette !== "string") diagnostics.push(typeDiagnostic("palette", "string"));
|
|
1825
|
-
else {
|
|
1826
|
-
config.palette = value.palette;
|
|
1827
|
-
if (!Object.hasOwn(config.palettes, value.palette)) {
|
|
1828
|
-
diagnostics.push(
|
|
1829
|
-
diagnostic("warning", "palette", `Unknown palette ${JSON.stringify(value.palette)}`)
|
|
1830
|
-
);
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
for (const name of MODULE_NAMES) {
|
|
1835
|
-
const moduleValue = value[name];
|
|
1836
|
-
if (moduleValue === void 0) continue;
|
|
1837
|
-
if (!isRecord(moduleValue)) {
|
|
1838
|
-
diagnostics.push(typeDiagnostic(name, "table"));
|
|
1839
|
-
continue;
|
|
1840
|
-
}
|
|
1841
|
-
normalizeModule(name, moduleValue, config, diagnostics);
|
|
1842
|
-
}
|
|
1843
|
-
validateFormatVariables(
|
|
1844
|
-
config.formatAst,
|
|
1845
|
-
/* @__PURE__ */ new Set([...MODULE_NAMES, "all"]),
|
|
1846
|
-
"format",
|
|
1847
|
-
diagnostics
|
|
1848
|
-
);
|
|
1849
|
-
validateStyleVariables(config.formatAst, /* @__PURE__ */ new Set(), "format", diagnostics);
|
|
1850
|
-
const palette = activePalette(config);
|
|
1851
|
-
validateLiteralStyles(config.formatAst, palette, "format", diagnostics);
|
|
1852
|
-
for (const definition of MODULE_DEFINITIONS) {
|
|
1853
|
-
const name = definition.name;
|
|
1854
|
-
const module = config.modules[name];
|
|
1855
|
-
validateFormatVariables(
|
|
1856
|
-
module.formatAst,
|
|
1857
|
-
new Set(MODULE_CONTENT_VARIABLES[name]),
|
|
1858
|
-
`${name}.format`,
|
|
1859
|
-
diagnostics
|
|
1860
|
-
);
|
|
1861
|
-
validateStyleVariables(
|
|
1862
|
-
module.formatAst,
|
|
1863
|
-
new Set(definition.styleVariables ?? ["style"]),
|
|
1864
|
-
`${name}.format`,
|
|
1865
|
-
diagnostics
|
|
1866
|
-
);
|
|
1867
|
-
validateLiteralStyles(module.formatAst, palette, `${name}.format`, diagnostics);
|
|
1868
|
-
if (definition.styleDefaults) {
|
|
1869
|
-
for (const field of Object.keys(definition.styleDefaults)) {
|
|
1870
|
-
validateModuleStyleField(name, field, module, palette, diagnostics);
|
|
1871
|
-
}
|
|
1872
|
-
} else if (!definition.displayDefaults) {
|
|
1873
|
-
validateModuleStyleField(name, "style", module, palette, diagnostics);
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
return { config, diagnostics };
|
|
1877
|
-
}
|
|
1878
|
-
function normalizeModule(name, value, config, diagnostics) {
|
|
1879
|
-
const definition = MODULE_DEFINITIONS.find((candidate) => candidate.name === name);
|
|
1880
|
-
if (!definition) return;
|
|
1881
|
-
const optionSchemas = definition.options ?? {};
|
|
1882
|
-
const known = /* @__PURE__ */ new Set(["format", "symbol", "disabled", ...Object.keys(optionSchemas)]);
|
|
1883
|
-
if (definition.styleDefaults) {
|
|
1884
|
-
for (const field of Object.keys(definition.styleDefaults)) known.add(field);
|
|
1885
|
-
} else if (!definition.displayDefaults) known.add("style");
|
|
1886
|
-
if (definition.displayDefaults) known.add("display");
|
|
1887
|
-
if (name === "extension_status") {
|
|
1888
|
-
known.add("separator");
|
|
1889
|
-
known.add("max_statuses");
|
|
1890
|
-
known.add("icons");
|
|
1891
|
-
}
|
|
1892
|
-
for (const key of Object.keys(value)) {
|
|
1893
|
-
if (!known.has(key)) diagnostics.push(unknownDiagnostic(`${name}.${key}`));
|
|
1894
|
-
}
|
|
1895
|
-
const module = config.modules[name];
|
|
1896
|
-
if (value.format !== void 0) {
|
|
1897
|
-
if (typeof value.format !== "string")
|
|
1898
|
-
diagnostics.push(typeDiagnostic(`${name}.format`, "string"));
|
|
1899
|
-
else {
|
|
1900
|
-
try {
|
|
1901
|
-
module.formatAst = parseFormat(value.format);
|
|
1902
|
-
module.format = value.format;
|
|
1903
|
-
} catch (error) {
|
|
1904
|
-
diagnostics.push(
|
|
1905
|
-
diagnostic(
|
|
1906
|
-
"warning",
|
|
1907
|
-
`${name}.format`,
|
|
1908
|
-
`Invalid format; using module default: ${formatError(error)}`
|
|
1909
|
-
)
|
|
1910
|
-
);
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
}
|
|
1914
|
-
if (value.symbol !== void 0) {
|
|
1915
|
-
if (typeof value.symbol !== "string") {
|
|
1916
|
-
diagnostics.push(typeDiagnostic(`${name}.symbol`, "string"));
|
|
1917
|
-
} else module.symbol = value.symbol;
|
|
1918
|
-
}
|
|
1919
|
-
if (definition.styleDefaults) {
|
|
1920
|
-
for (const field of Object.keys(definition.styleDefaults)) {
|
|
1921
|
-
if (value[field] === void 0) continue;
|
|
1922
|
-
if (typeof value[field] !== "string") {
|
|
1923
|
-
diagnostics.push(typeDiagnostic(`${name}.${field}`, "string"));
|
|
1924
|
-
} else module.styles[field] = value[field];
|
|
1925
|
-
}
|
|
1926
|
-
} else if (!definition.displayDefaults && value.style !== void 0) {
|
|
1927
|
-
if (typeof value.style !== "string") {
|
|
1928
|
-
diagnostics.push(typeDiagnostic(`${name}.style`, "string"));
|
|
1929
|
-
} else module.style = value.style;
|
|
1930
|
-
}
|
|
1931
|
-
if (definition.displayDefaults && value.display !== void 0) {
|
|
1932
|
-
module.display = normalizeDisplay(
|
|
1933
|
-
name,
|
|
1934
|
-
value.display,
|
|
1935
|
-
definition.displayDefaults,
|
|
1936
|
-
activePalette(config),
|
|
1937
|
-
diagnostics
|
|
1938
|
-
);
|
|
1939
|
-
}
|
|
1940
|
-
if (value.disabled !== void 0) {
|
|
1941
|
-
if (typeof value.disabled !== "boolean") {
|
|
1942
|
-
diagnostics.push(typeDiagnostic(`${name}.disabled`, "boolean"));
|
|
1943
|
-
} else module.disabled = value.disabled;
|
|
1944
|
-
}
|
|
1945
|
-
for (const [key, schema] of Object.entries(optionSchemas)) {
|
|
1946
|
-
if (value[key] === void 0) continue;
|
|
1947
|
-
const normalized = normalizeModuleOption(value[key], schema);
|
|
1948
|
-
if (normalized.ok) module.options[key] = normalized.value;
|
|
1949
|
-
else diagnostics.push(diagnostic("warning", `${name}.${key}`, normalized.message));
|
|
1950
|
-
}
|
|
1951
|
-
if (name !== "extension_status") return;
|
|
1952
|
-
if (value.separator !== void 0) {
|
|
1953
|
-
if (typeof value.separator !== "string") {
|
|
1954
|
-
diagnostics.push(typeDiagnostic("extension_status.separator", "string"));
|
|
1955
|
-
} else config.extensionStatus.separator = value.separator;
|
|
1956
|
-
}
|
|
1957
|
-
if (value.max_statuses !== void 0) {
|
|
1958
|
-
if (typeof value.max_statuses !== "number" || !Number.isInteger(value.max_statuses) || value.max_statuses < 0 || value.max_statuses > 100) {
|
|
1959
|
-
diagnostics.push(
|
|
1960
|
-
diagnostic(
|
|
1961
|
-
"warning",
|
|
1962
|
-
"extension_status.max_statuses",
|
|
1963
|
-
"Expected an integer from 0 through 100"
|
|
1964
|
-
)
|
|
1965
|
-
);
|
|
1966
|
-
} else config.extensionStatus.maxStatuses = value.max_statuses;
|
|
1967
|
-
}
|
|
1968
|
-
if (value.icons !== void 0) {
|
|
1969
|
-
if (!isRecord(value.icons)) diagnostics.push(typeDiagnostic("extension_status.icons", "table"));
|
|
1970
|
-
else {
|
|
1971
|
-
config.extensionStatus.icons = Object.fromEntries(
|
|
1972
|
-
Object.entries(value.icons).flatMap(([key, icon]) => {
|
|
1973
|
-
if (typeof icon === "string") return [[key, icon]];
|
|
1974
|
-
diagnostics.push(typeDiagnostic(`extension_status.icons.${key}`, "string"));
|
|
1975
|
-
return [];
|
|
1976
|
-
})
|
|
1977
|
-
);
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
function validateConfigDocument(settingsPath, rawDocument) {
|
|
1982
|
-
let parsed;
|
|
1983
|
-
try {
|
|
1984
|
-
parsed = parseToml(rawDocument);
|
|
1985
|
-
} catch (error) {
|
|
1986
|
-
throw new Error(`Unable to parse TOML: ${formatError(error)}`);
|
|
1987
|
-
}
|
|
1988
|
-
const normalized = normalizeConfig(parsed);
|
|
1989
|
-
if (normalized.diagnostics.some((item) => item.severity === "error")) {
|
|
1990
|
-
throw new Error(normalized.diagnostics.map((item) => item.message).join("\n"));
|
|
1991
|
-
}
|
|
1992
|
-
return {
|
|
1993
|
-
...normalized,
|
|
1994
|
-
source: "user",
|
|
1995
|
-
settingsPath,
|
|
1996
|
-
rawDocument
|
|
1997
|
-
};
|
|
1998
|
-
}
|
|
1999
|
-
function atomicSaveConfigDocument(settingsPath, rawDocument, overrides = {}) {
|
|
2000
|
-
const validated = validateConfigDocument(settingsPath, rawDocument);
|
|
2001
|
-
return {
|
|
2002
|
-
...validated,
|
|
2003
|
-
fileIdentity: atomicWriteConfigDocument(settingsPath, rawDocument, overrides)
|
|
2004
|
-
};
|
|
2005
|
-
}
|
|
2006
|
-
function atomicRestoreConfigDocument(settingsPath, rawDocument, overrides = {}) {
|
|
2007
|
-
atomicWriteConfigDocument(settingsPath, rawDocument, overrides);
|
|
2008
|
-
}
|
|
2009
|
-
function removeConfigDocumentIfMatches(settingsPath, expectedRawDocument, expectedIdentity, overrides = {}) {
|
|
2010
|
-
const quarantinePath = join(
|
|
2011
|
-
dirname(settingsPath),
|
|
2012
|
-
`.${CONFIG_FILE_NAME}.${randomUUID()}.rollback`
|
|
2013
|
-
);
|
|
2014
|
-
const before = lstatSync(settingsPath);
|
|
2015
|
-
if (before.dev !== expectedIdentity.dev || before.ino !== expectedIdentity.ino) {
|
|
2016
|
-
throw new Error("Starship settings changed concurrently; the newer file was preserved");
|
|
2017
|
-
}
|
|
2018
|
-
renameSync(settingsPath, quarantinePath);
|
|
2019
|
-
const quarantined = lstatSync(quarantinePath);
|
|
2020
|
-
const quarantinedSavedFile = quarantined.isFile() && !quarantined.isSymbolicLink() && quarantined.dev === expectedIdentity.dev && quarantined.ino === expectedIdentity.ino;
|
|
2021
|
-
if (quarantinedSavedFile && readFileSync(quarantinePath, "utf8") === expectedRawDocument) {
|
|
2022
|
-
(overrides.rmSync ?? rmSync)(quarantinePath);
|
|
2023
|
-
return;
|
|
2024
|
-
}
|
|
2025
|
-
if (quarantinedSavedFile && !pathEntryExists(settingsPath)) {
|
|
2026
|
-
try {
|
|
2027
|
-
renameSync(quarantinePath, settingsPath);
|
|
2028
|
-
} catch {
|
|
2029
|
-
}
|
|
2030
|
-
}
|
|
2031
|
-
throw new Error("Starship settings changed concurrently; the newer file was preserved");
|
|
2032
|
-
}
|
|
2033
|
-
function atomicWriteConfigDocument(settingsPath, rawDocument, overrides) {
|
|
2034
|
-
const fs = { mkdirSync, writeFileSync, renameSync, rmSync, ...overrides };
|
|
2035
|
-
const replaceExisting = pathEntryExists(settingsPath);
|
|
2036
|
-
fs.mkdirSync(dirname(settingsPath), { recursive: true });
|
|
2037
|
-
const tempPath = join(dirname(settingsPath), `.${CONFIG_FILE_NAME}.${randomUUID()}.tmp`);
|
|
2038
|
-
try {
|
|
2039
|
-
fs.writeFileSync(tempPath, rawDocument, { encoding: "utf8", flag: "wx" });
|
|
2040
|
-
const info = lstatSync(tempPath);
|
|
2041
|
-
if (!replaceExisting && pathEntryExists(settingsPath)) {
|
|
2042
|
-
throw new Error(`${CONFIG_FILE_NAME} was created concurrently; reopen settings and retry.`);
|
|
2043
|
-
}
|
|
2044
|
-
fs.renameSync(tempPath, settingsPath);
|
|
2045
|
-
return { dev: info.dev, ino: info.ino };
|
|
2046
|
-
} finally {
|
|
2047
|
-
try {
|
|
2048
|
-
fs.rmSync(tempPath, { force: true });
|
|
2049
|
-
} catch {
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
function cloneBuiltInConfig() {
|
|
2054
|
-
return {
|
|
2055
|
-
...BUILT_IN_CONFIG,
|
|
2056
|
-
formatAst: structuredClone(BUILT_IN_CONFIG.formatAst),
|
|
2057
|
-
palettes: Object.fromEntries(
|
|
2058
|
-
Object.entries(BUILT_IN_CONFIG.palettes).map(([name, colors]) => [name, { ...colors }])
|
|
2059
|
-
),
|
|
2060
|
-
modules: Object.fromEntries(
|
|
2061
|
-
MODULE_NAMES.map((name) => [
|
|
2062
|
-
name,
|
|
2063
|
-
{
|
|
2064
|
-
...BUILT_IN_CONFIG.modules[name],
|
|
2065
|
-
formatAst: structuredClone(BUILT_IN_CONFIG.modules[name].formatAst),
|
|
2066
|
-
styles: { ...BUILT_IN_CONFIG.modules[name].styles },
|
|
2067
|
-
display: structuredClone(BUILT_IN_CONFIG.modules[name].display),
|
|
2068
|
-
options: structuredClone(BUILT_IN_CONFIG.modules[name].options)
|
|
2069
|
-
}
|
|
2070
|
-
])
|
|
2071
|
-
),
|
|
2072
|
-
extensionStatus: {
|
|
2073
|
-
...BUILT_IN_CONFIG.extensionStatus,
|
|
2074
|
-
icons: { ...BUILT_IN_CONFIG.extensionStatus.icons }
|
|
2075
|
-
}
|
|
2076
|
-
};
|
|
2077
|
-
}
|
|
2078
|
-
function validateFormatVariables(ast, allowed, path, diagnostics) {
|
|
2079
|
-
for (const variable of formatVariables(ast)) {
|
|
2080
|
-
if (allowed.has(variable)) continue;
|
|
2081
|
-
diagnostics.push(
|
|
2082
|
-
diagnostic(
|
|
2083
|
-
"warning",
|
|
2084
|
-
path,
|
|
2085
|
-
`Unknown variable ${JSON.stringify(variable)} in ${path} was ignored`
|
|
2086
|
-
)
|
|
2087
|
-
);
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
function validateStyleVariables(ast, allowed, path, diagnostics) {
|
|
2091
|
-
for (const variable of styleVariables(ast)) {
|
|
2092
|
-
if (allowed.has(variable)) continue;
|
|
2093
|
-
diagnostics.push(
|
|
2094
|
-
diagnostic(
|
|
2095
|
-
"warning",
|
|
2096
|
-
path,
|
|
2097
|
-
`Unknown style variable ${JSON.stringify(variable)} in ${path} was ignored`
|
|
2098
|
-
)
|
|
2099
|
-
);
|
|
2100
|
-
}
|
|
2101
|
-
}
|
|
2102
|
-
function validateModuleStyleField(name, field, module, palette, diagnostics) {
|
|
2103
|
-
const style = field === "style" ? module.style : module.styles[field];
|
|
2104
|
-
if (style === void 0 || isValidStyle(style, palette)) return;
|
|
2105
|
-
diagnostics.push(
|
|
2106
|
-
diagnostic(
|
|
2107
|
-
"warning",
|
|
2108
|
-
`${name}.${field}`,
|
|
2109
|
-
`Invalid style ${JSON.stringify(style)}; using the module default`
|
|
2110
|
-
)
|
|
2111
|
-
);
|
|
2112
|
-
if (field === "style") module.style = BUILT_IN_CONFIG.modules[name].style;
|
|
2113
|
-
else {
|
|
2114
|
-
const fallback = BUILT_IN_CONFIG.modules[name].styles[field];
|
|
2115
|
-
if (fallback !== void 0) module.styles[field] = fallback;
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
function normalizeDisplay(name, value, defaults, palette, diagnostics) {
|
|
2119
|
-
if (!Array.isArray(value)) {
|
|
2120
|
-
diagnostics.push(typeDiagnostic(`${name}.display`, "array of tables"));
|
|
2121
|
-
return defaults.map((entry) => ({ ...entry }));
|
|
2122
|
-
}
|
|
2123
|
-
const result = [];
|
|
2124
|
-
for (const [index, entry] of value.entries()) {
|
|
2125
|
-
const path = `${name}.display.${index}`;
|
|
2126
|
-
if (!isRecord(entry)) {
|
|
2127
|
-
diagnostics.push(typeDiagnostic(path, "table"));
|
|
2128
|
-
continue;
|
|
2129
|
-
}
|
|
2130
|
-
for (const field of Object.keys(entry)) {
|
|
2131
|
-
if (!(/* @__PURE__ */ new Set(["threshold", "style", "hidden"])).has(field)) {
|
|
2132
|
-
diagnostics.push(unknownDiagnostic(`${path}.${field}`));
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
let valid = true;
|
|
2136
|
-
if (typeof entry.threshold !== "number" || !Number.isFinite(entry.threshold)) {
|
|
2137
|
-
diagnostics.push(diagnostic("warning", `${path}.threshold`, "Expected a finite number"));
|
|
2138
|
-
valid = false;
|
|
2139
|
-
}
|
|
2140
|
-
if (typeof entry.style !== "string" || !isValidStyle(entry.style, palette)) {
|
|
2141
|
-
diagnostics.push(
|
|
2142
|
-
diagnostic("warning", `${path}.style`, "Expected a valid Starship style string")
|
|
2143
|
-
);
|
|
2144
|
-
valid = false;
|
|
2145
|
-
}
|
|
2146
|
-
if (typeof entry.hidden !== "boolean") {
|
|
2147
|
-
diagnostics.push(typeDiagnostic(`${path}.hidden`, "boolean"));
|
|
2148
|
-
valid = false;
|
|
2149
|
-
}
|
|
2150
|
-
if (valid) {
|
|
2151
|
-
result.push({
|
|
2152
|
-
threshold: entry.threshold,
|
|
2153
|
-
style: entry.style,
|
|
2154
|
-
hidden: entry.hidden
|
|
2155
|
-
});
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
if (result.length > 0) return result;
|
|
2159
|
-
diagnostics.push(
|
|
2160
|
-
diagnostic("warning", `${name}.display`, "Expected at least one valid entry; using defaults")
|
|
2161
|
-
);
|
|
2162
|
-
return defaults.map((entry) => ({ ...entry }));
|
|
2163
|
-
}
|
|
2164
|
-
function validateLiteralStyles(ast, palette, path, diagnostics) {
|
|
2165
|
-
for (const node of ast) {
|
|
2166
|
-
if (node.type === "group" && node.style.every((part) => part.type === "text")) {
|
|
2167
|
-
const style = node.style.map((part) => part.type === "text" ? part.value : "").join("");
|
|
2168
|
-
if (!isValidStyle(style, palette)) {
|
|
2169
|
-
diagnostics.push(
|
|
2170
|
-
diagnostic(
|
|
2171
|
-
"warning",
|
|
2172
|
-
path,
|
|
2173
|
-
`Invalid literal style ${JSON.stringify(style)}; rendered unstyled`
|
|
2174
|
-
)
|
|
2175
|
-
);
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
if (node.type === "group" || node.type === "conditional") {
|
|
2179
|
-
validateLiteralStyles(node.children, palette, path, diagnostics);
|
|
2180
|
-
}
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
function normalizeModuleOption(value, schema) {
|
|
2184
|
-
switch (schema.kind) {
|
|
2185
|
-
case "string":
|
|
2186
|
-
return typeof value === "string" && (schema.allowEmpty !== false || value.length > 0) ? { ok: true, value } : { ok: false, message: "Expected a non-empty string; using the default value" };
|
|
2187
|
-
case "string-enum":
|
|
2188
|
-
return typeof value === "string" && schema.values.includes(value) ? { ok: true, value } : {
|
|
2189
|
-
ok: false,
|
|
2190
|
-
message: `Expected one of: ${schema.values.join(", ")}; using the default value`
|
|
2191
|
-
};
|
|
2192
|
-
case "boolean":
|
|
2193
|
-
return typeof value === "boolean" ? { ok: true, value } : { ok: false, message: "Expected boolean; using the default value" };
|
|
2194
|
-
case "integer":
|
|
2195
|
-
return typeof value === "number" && Number.isInteger(value) && value >= schema.minimum && value <= schema.maximum ? { ok: true, value } : {
|
|
2196
|
-
ok: false,
|
|
2197
|
-
message: `Expected an integer from ${schema.minimum} through ${schema.maximum}; using the default value`
|
|
2198
|
-
};
|
|
2199
|
-
case "string-array": {
|
|
2200
|
-
if (!Array.isArray(value) || value.some(
|
|
2201
|
-
(item) => typeof item !== "string" || item.length === 0 || !schema.allowNegative && item.startsWith("!")
|
|
2202
|
-
)) {
|
|
2203
|
-
return {
|
|
2204
|
-
ok: false,
|
|
2205
|
-
message: "Expected an array of valid strings; using the default value"
|
|
2206
|
-
};
|
|
2207
|
-
}
|
|
2208
|
-
return { ok: true, value: [...value] };
|
|
2209
|
-
}
|
|
2210
|
-
case "string-map": {
|
|
2211
|
-
if (!isRecord(value) || Object.values(value).some((item) => typeof item !== "string")) {
|
|
2212
|
-
return { ok: false, message: "Expected a table of strings; using the default value" };
|
|
2213
|
-
}
|
|
2214
|
-
const result = {};
|
|
2215
|
-
for (const [key, item] of Object.entries(value)) setOwn(result, key, item);
|
|
2216
|
-
return { ok: true, value: result };
|
|
2217
|
-
}
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
function cloneOptionValue(value) {
|
|
2221
|
-
return typeof value === "object" ? structuredClone(value) : value;
|
|
2222
|
-
}
|
|
2223
|
-
function setOwn(record, key, value) {
|
|
2224
|
-
Object.defineProperty(record, key, {
|
|
2225
|
-
value,
|
|
2226
|
-
writable: true,
|
|
2227
|
-
enumerable: true,
|
|
2228
|
-
configurable: true
|
|
2229
|
-
});
|
|
2230
|
-
}
|
|
2231
|
-
function isRecord(value) {
|
|
2232
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2233
|
-
}
|
|
2234
|
-
function typeDiagnostic(path, type) {
|
|
2235
|
-
return diagnostic("warning", path, `Expected ${type}; using the default value`);
|
|
2236
|
-
}
|
|
2237
|
-
function unknownDiagnostic(path) {
|
|
2238
|
-
return diagnostic("warning", path, `Unknown setting ${JSON.stringify(path)} was ignored`);
|
|
2239
|
-
}
|
|
2240
|
-
function diagnostic(severity, path, message) {
|
|
2241
|
-
return { severity, path, message };
|
|
2242
|
-
}
|
|
2243
|
-
function pathEntryExists(path) {
|
|
2244
|
-
try {
|
|
2245
|
-
lstatSync(path);
|
|
2246
|
-
return true;
|
|
2247
|
-
} catch (error) {
|
|
2248
|
-
if (error.code === "ENOENT") return false;
|
|
2249
|
-
throw error;
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
function formatError(error) {
|
|
2253
|
-
return error instanceof Error ? error.message : String(error);
|
|
2254
|
-
}
|
|
2255
|
-
function activePalette(config) {
|
|
2256
|
-
return ownPalette(config.palettes, config.palette) ?? {};
|
|
2257
|
-
}
|
|
2258
|
-
function ownPalette(palettes, name) {
|
|
2259
|
-
return name !== void 0 && Object.hasOwn(palettes, name) ? palettes[name] : void 0;
|
|
2260
|
-
}
|
|
2261
|
-
|
|
2262
|
-
// src/modules/render.ts
|
|
2263
|
-
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
2264
|
-
function renderStatusline(config, runtime, width = 80) {
|
|
2265
|
-
const palette = activePalette(config);
|
|
2266
|
-
const modules = {};
|
|
2267
|
-
const layoutModules = {};
|
|
2268
|
-
for (const name of MODULE_NAMES) {
|
|
2269
|
-
modules[name] = [];
|
|
2270
|
-
layoutModules[name] = [];
|
|
2271
|
-
}
|
|
2272
|
-
for (const definition of MODULE_DEFINITIONS) {
|
|
2273
|
-
const name = definition.name;
|
|
2274
|
-
const module = config.modules[name];
|
|
2275
|
-
const values = definition.values(valueContext(config, name, runtime));
|
|
2276
|
-
if (!values) continue;
|
|
2277
|
-
const styleVariables2 = definition.resolveStyleVariables ? definition.resolveStyleVariables({
|
|
2278
|
-
runtime,
|
|
2279
|
-
values,
|
|
2280
|
-
style: module.style,
|
|
2281
|
-
styles: module.styles,
|
|
2282
|
-
display: module.display
|
|
2283
|
-
}) : { style: module.style };
|
|
2284
|
-
if (!styleVariables2) continue;
|
|
2285
|
-
const contentValues = Object.fromEntries(
|
|
2286
|
-
definition.variables.flatMap(
|
|
2287
|
-
(variable) => variable !== "symbol" && Object.hasOwn(values, variable) ? [[variable, values[variable]]] : []
|
|
2288
|
-
)
|
|
2289
|
-
);
|
|
2290
|
-
const rendered = renderModule(module, contentValues, styleVariables2, palette);
|
|
2291
|
-
modules[name] = rendered;
|
|
2292
|
-
layoutModules[name] = definition.layout === "fill" && !module.disabled ? [{ type: "fill", pattern: rendered }] : rendered;
|
|
2293
|
-
}
|
|
2294
|
-
const explicitModules = formatVariables(config.formatAst);
|
|
2295
|
-
const all = MODULE_NAMES.flatMap(
|
|
2296
|
-
(name) => explicitModules.has(name) || config.modules[name].disabled ? [] : layoutModules[name]
|
|
2297
|
-
);
|
|
2298
|
-
const rootVariables = { all };
|
|
2299
|
-
for (const name of MODULE_NAMES) rootVariables[name] = layoutModules[name];
|
|
2300
|
-
const layout = renderFormat(config.formatAst, { variables: rootVariables, palette });
|
|
2301
|
-
const chunks = resolveFillLayout(layout, width);
|
|
2302
|
-
return {
|
|
2303
|
-
ansi: renderChunksToAnsi(chunks),
|
|
2304
|
-
chunks,
|
|
2305
|
-
modules
|
|
2306
|
-
};
|
|
2307
|
-
}
|
|
2308
|
-
function valueContext(config, name, runtime) {
|
|
2309
|
-
return {
|
|
2310
|
-
runtime,
|
|
2311
|
-
symbol: config.modules[name].symbol,
|
|
2312
|
-
options: config.modules[name].options,
|
|
2313
|
-
extensionStatus: config.extensionStatus
|
|
2314
|
-
};
|
|
2315
|
-
}
|
|
2316
|
-
function renderModule(module, values, styleVariables2, palette) {
|
|
2317
|
-
if (module.disabled) return [];
|
|
2318
|
-
return renderFormat(module.formatAst, {
|
|
2319
|
-
variables: { symbol: module.symbol, ...values },
|
|
2320
|
-
styleVariables: styleVariables2,
|
|
2321
|
-
palette
|
|
2322
|
-
}).filter((chunk) => !isFillChunk(chunk));
|
|
2323
|
-
}
|
|
2324
|
-
function reachableModuleRequirements(config) {
|
|
2325
|
-
const rootVariables = formatVariables(config.formatAst);
|
|
2326
|
-
const includeAll = rootVariables.has("all");
|
|
2327
|
-
const requirements = /* @__PURE__ */ new Map();
|
|
2328
|
-
for (const definition of MODULE_DEFINITIONS) {
|
|
2329
|
-
if (config.modules[definition.name].disabled) continue;
|
|
2330
|
-
if (!includeAll && !rootVariables.has(definition.name)) continue;
|
|
2331
|
-
requirements.set(definition.name, formatVariables(config.modules[definition.name].formatAst));
|
|
2332
|
-
}
|
|
2333
|
-
return requirements;
|
|
2334
|
-
}
|
|
2335
|
-
function resolveFillLayout(layout, width) {
|
|
2336
|
-
const lines = splitLogicalLines(layout);
|
|
2337
|
-
const resolved = [];
|
|
2338
|
-
for (const [lineIndex, line] of lines.entries()) {
|
|
2339
|
-
const fills = line.filter(isFillChunk);
|
|
2340
|
-
const fixedWidth = line.reduce(
|
|
2341
|
-
(total, chunk) => total + (isFillChunk(chunk) ? 0 : visibleWidth(renderChunksToAnsi([chunk]))),
|
|
2342
|
-
0
|
|
2343
|
-
);
|
|
2344
|
-
const remaining = Math.max(0, width - fixedWidth);
|
|
2345
|
-
const base = fills.length > 0 ? Math.floor(remaining / fills.length) : 0;
|
|
2346
|
-
let remainder = fills.length > 0 ? remaining % fills.length : 0;
|
|
2347
|
-
for (const chunk of line) {
|
|
2348
|
-
if (!isFillChunk(chunk)) {
|
|
2349
|
-
resolved.push(chunk);
|
|
2350
|
-
continue;
|
|
2351
|
-
}
|
|
2352
|
-
const allocation = base + (remainder > 0 ? 1 : 0);
|
|
2353
|
-
if (remainder > 0) remainder -= 1;
|
|
2354
|
-
resolved.push(...expandFill(chunk.pattern, allocation));
|
|
2355
|
-
}
|
|
2356
|
-
if (lineIndex < lines.length - 1) resolved.push({ text: "\n" });
|
|
2357
|
-
}
|
|
2358
|
-
return resolved;
|
|
2359
|
-
}
|
|
2360
|
-
function splitLogicalLines(layout) {
|
|
2361
|
-
const lines = [[]];
|
|
2362
|
-
for (const chunk of layout) {
|
|
2363
|
-
if (isFillChunk(chunk)) {
|
|
2364
|
-
lines.at(-1)?.push(chunk);
|
|
2365
|
-
continue;
|
|
2366
|
-
}
|
|
2367
|
-
const parts = chunk.text.split("\n");
|
|
2368
|
-
for (const [index, text] of parts.entries()) {
|
|
2369
|
-
if (text) lines.at(-1)?.push({ ...chunk, text });
|
|
2370
|
-
if (index < parts.length - 1) lines.push([]);
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
return lines;
|
|
2374
|
-
}
|
|
2375
|
-
function expandFill(pattern, width) {
|
|
2376
|
-
if (width <= 0) return [];
|
|
2377
|
-
const patternWidth = visibleWidth(renderChunksToAnsi(pattern));
|
|
2378
|
-
if (patternWidth <= 0) return [{ text: " ".repeat(width), style: pattern[0]?.style }];
|
|
2379
|
-
const repetitions = Math.floor(width / patternWidth);
|
|
2380
|
-
const result = [];
|
|
2381
|
-
for (let index = 0; index < repetitions; index += 1) {
|
|
2382
|
-
result.push(...pattern.map((chunk) => ({ ...chunk })));
|
|
2383
|
-
}
|
|
2384
|
-
const remainder = width - repetitions * patternWidth;
|
|
2385
|
-
if (remainder > 0) result.push({ text: " ".repeat(remainder), style: pattern.at(-1)?.style });
|
|
2386
|
-
return result;
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
// src/modules/inspection.ts
|
|
2390
|
-
import { stripVTControlCharacters } from "node:util";
|
|
2391
|
-
function inspectStatuslineModules(config, runtime, width = 80) {
|
|
2392
|
-
const rendered = renderStatusline(config, runtime, width);
|
|
2393
|
-
const requirements = reachableModuleRequirements(config);
|
|
2394
|
-
const rootVariables = formatVariables(config.formatAst);
|
|
2395
|
-
const includeAll = rootVariables.has("all");
|
|
2396
|
-
const modules = MODULE_DEFINITIONS.map((definition) => {
|
|
2397
|
-
const module = config.modules[definition.name];
|
|
2398
|
-
const reachable = requirements.has(definition.name);
|
|
2399
|
-
const preview = plainPreview(
|
|
2400
|
-
rendered.modules[definition.name].map((chunk) => chunk.text).join("")
|
|
2401
|
-
);
|
|
2402
|
-
const state = module.disabled ? "Disabled" : !reachable ? "Not in format" : preview.length > 0 ? "Showing" : "Empty";
|
|
2403
|
-
return moduleInspection(
|
|
2404
|
-
config,
|
|
2405
|
-
definition,
|
|
2406
|
-
state,
|
|
2407
|
-
preview,
|
|
2408
|
-
includeAll || rootVariables.has(definition.name),
|
|
2409
|
-
reachable
|
|
2410
|
-
);
|
|
2411
|
-
});
|
|
2412
|
-
return {
|
|
2413
|
-
modules,
|
|
2414
|
-
showing: modules.filter((module) => module.state === "Showing")
|
|
2415
|
-
};
|
|
2416
|
-
}
|
|
2417
|
-
function inspectUnavailableModules(config) {
|
|
2418
|
-
const requirements = reachableModuleRequirements(config);
|
|
2419
|
-
const rootVariables = formatVariables(config.formatAst);
|
|
2420
|
-
const includeAll = rootVariables.has("all");
|
|
2421
|
-
return {
|
|
2422
|
-
modules: MODULE_DEFINITIONS.map((definition) => {
|
|
2423
|
-
const module = config.modules[definition.name];
|
|
2424
|
-
const reachable = requirements.has(definition.name);
|
|
2425
|
-
const state = module.disabled ? "Disabled" : reachable ? "Unavailable" : "Not in format";
|
|
2426
|
-
return moduleInspection(
|
|
2427
|
-
config,
|
|
2428
|
-
definition,
|
|
2429
|
-
state,
|
|
2430
|
-
"",
|
|
2431
|
-
includeAll || rootVariables.has(definition.name),
|
|
2432
|
-
reachable
|
|
2433
|
-
);
|
|
2434
|
-
}),
|
|
2435
|
-
showing: []
|
|
2436
|
-
};
|
|
2437
|
-
}
|
|
2438
|
-
function moduleInspection(config, definition, state, preview, rootReferenced, reachable) {
|
|
2439
|
-
const module = config.modules[definition.name];
|
|
2440
|
-
return {
|
|
2441
|
-
name: definition.name,
|
|
2442
|
-
description: definition.description,
|
|
2443
|
-
state,
|
|
2444
|
-
preview,
|
|
2445
|
-
variables: [...definition.variables],
|
|
2446
|
-
styleFields: ["style", ...Object.keys(module.styles)],
|
|
2447
|
-
displayRules: module.display.map(
|
|
2448
|
-
(rule) => `${rule.threshold}: ${rule.hidden ? "hidden" : rule.style || "unstyled"}`
|
|
2449
|
-
),
|
|
2450
|
-
rootReferenced,
|
|
2451
|
-
reachable,
|
|
2452
|
-
reason: inspectionReason(state)
|
|
2453
|
-
};
|
|
2454
|
-
}
|
|
2455
|
-
function inspectionReason(state) {
|
|
2456
|
-
switch (state) {
|
|
2457
|
-
case "Showing":
|
|
2458
|
-
return "Rendered in the current footer.";
|
|
2459
|
-
case "Empty":
|
|
2460
|
-
return "Referenced by the root format, but the current snapshot produced no output.";
|
|
2461
|
-
case "Disabled":
|
|
2462
|
-
return "Disabled by this module's configuration.";
|
|
2463
|
-
case "Not in format":
|
|
2464
|
-
return "Not referenced by the root format or $all.";
|
|
2465
|
-
case "Unavailable":
|
|
2466
|
-
return "Current footer inspection is unavailable; no collector failure was inferred.";
|
|
2467
|
-
}
|
|
2468
|
-
}
|
|
2469
|
-
function plainPreview(value) {
|
|
2470
|
-
return Array.from(stripVTControlCharacters(value), (character) => {
|
|
2471
|
-
const codePoint = character.codePointAt(0) ?? 0;
|
|
2472
|
-
if (character === "\n") return character;
|
|
2473
|
-
return codePoint <= 31 || codePoint >= 127 && codePoint <= 159 ? " " : character;
|
|
2474
|
-
}).join("");
|
|
2475
|
-
}
|
|
2476
|
-
|
|
2477
|
-
export {
|
|
2478
|
-
STARSHIP_SUBCOMMANDS,
|
|
2479
|
-
completeStarshipArguments,
|
|
2480
|
-
BUILT_IN_EXAMPLE,
|
|
2481
|
-
settingsFilePath,
|
|
2482
|
-
loadStarshipConfig,
|
|
2483
|
-
validateConfigDocument,
|
|
2484
|
-
atomicSaveConfigDocument,
|
|
2485
|
-
atomicRestoreConfigDocument,
|
|
2486
|
-
removeConfigDocumentIfMatches,
|
|
2487
|
-
renderStatusline,
|
|
2488
|
-
reachableModuleRequirements,
|
|
2489
|
-
inspectStatuslineModules,
|
|
2490
|
-
inspectUnavailableModules
|
|
2491
|
-
};
|
|
2492
|
-
//# sourceMappingURL=chunk-Q6DLIM7H.ts.map
|