@narumitw/pi-starship 0.55.0 → 0.55.2
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 +21 -36
- package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
- package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
- package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
- package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
- package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
- package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
- package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
- package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
- package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
- package/dist/chunks/commands-ATILSUVK.js.map +7 -0
- package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
- package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
- package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
- package/dist/chunks/development-OUYXDPBS.js.map +7 -0
- package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
- package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
- package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
- package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
- package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
- package/dist/chunks/package-YXRZQAOV.js.map +7 -0
- package/dist/index.ts +38 -53
- package/dist/index.ts.map +2 -2
- package/package.json +60 -61
- package/skills/configuring-pi-starship/references/runtime-and-security.md +5 -1
- package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
- package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
- package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
- package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
- package/src/command-configuration.ts +267 -286
- package/src/command-contract.ts +6 -6
- package/src/command-inspector.ts +27 -27
- package/src/command-preset-picker.ts +45 -50
- package/src/command-preview.ts +153 -166
- package/src/commands.ts +588 -618
- package/src/config.ts +580 -660
- package/src/effective-config.ts +46 -48
- package/src/format/formatter.ts +211 -227
- package/src/format/style.ts +205 -216
- package/src/modules/activity.ts +74 -74
- package/src/modules/brand.ts +9 -9
- package/src/modules/cache.ts +18 -18
- package/src/modules/catalog.ts +79 -83
- package/src/modules/cloud.ts +54 -54
- package/src/modules/context.ts +27 -27
- package/src/modules/cost.ts +23 -23
- package/src/modules/deployment.ts +45 -45
- package/src/modules/development.ts +80 -81
- package/src/modules/directory.ts +89 -113
- package/src/modules/display.ts +9 -9
- package/src/modules/execution.ts +62 -69
- package/src/modules/extension-status.ts +59 -64
- package/src/modules/fill.ts +10 -10
- package/src/modules/git/branch.ts +26 -26
- package/src/modules/git/commit.ts +21 -23
- package/src/modules/git/metrics.ts +22 -22
- package/src/modules/git/runtime.ts +299 -334
- package/src/modules/git/state.ts +17 -17
- package/src/modules/git/status.ts +77 -79
- package/src/modules/git/worktree.ts +10 -12
- package/src/modules/github-pr.ts +20 -20
- package/src/modules/helpers.ts +3 -3
- package/src/modules/index.ts +21 -21
- package/src/modules/inspection.ts +101 -108
- package/src/modules/languages.ts +52 -59
- package/src/modules/model.ts +57 -67
- package/src/modules/package.ts +12 -12
- package/src/modules/provider.ts +22 -24
- package/src/modules/render.ts +124 -140
- package/src/modules/thinking.ts +27 -26
- package/src/modules/time.ts +10 -13
- package/src/modules/tokens.ts +13 -13
- package/src/modules/truncation.ts +14 -17
- package/src/modules/turn.ts +9 -9
- package/src/modules/types.ts +125 -132
- package/src/modules/workspace-helpers.ts +4 -7
- package/src/pi-starship.ts +567 -571
- package/src/presets/catalog.ts +113 -113
- package/src/runtime/cloud.ts +122 -150
- package/src/runtime/command.ts +106 -108
- package/src/runtime/deployment.ts +150 -179
- package/src/runtime/development.ts +107 -124
- package/src/runtime/execution.ts +110 -124
- package/src/runtime/github-pr.ts +223 -252
- package/src/runtime/helpers.ts +186 -199
- package/src/runtime/languages.ts +149 -180
- package/src/runtime/package.ts +74 -87
- package/src/runtime/refresh-controller.ts +82 -86
- package/src/runtime/types.ts +38 -38
- package/src/runtime/workspace.ts +108 -116
- package/src/usage.ts +40 -40
- package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
- package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
- package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
- package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
- package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
- package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
- package/dist/chunks/development-BERD42HW.js.map +0 -7
- package/dist/chunks/execution-42JTEY3N.js.map +0 -7
- package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
- package/dist/chunks/package-LG5H7BBM.js.map +0 -7
package/src/modules/languages.ts
CHANGED
|
@@ -2,86 +2,79 @@ import { defineModule, type ModuleDefinition } from "./types.js";
|
|
|
2
2
|
import { workspaceModuleValues } from "./workspace-helpers.js";
|
|
3
3
|
|
|
4
4
|
const detectionOptions = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
version_format: { kind: "string", default: "v$raw" },
|
|
6
|
+
detect_files: { kind: "string-array", default: [], allowNegative: true },
|
|
7
|
+
detect_extensions: { kind: "string-array", default: [], allowNegative: true },
|
|
8
|
+
detect_folders: { kind: "string-array", default: [], allowNegative: true },
|
|
9
9
|
} as const;
|
|
10
10
|
|
|
11
11
|
function languageModule<const Name extends string>(definition: {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
name: Name;
|
|
13
|
+
variables: readonly string[];
|
|
14
|
+
format: string;
|
|
15
|
+
symbol: string;
|
|
16
|
+
style: string;
|
|
17
17
|
}): ModuleDefinition<Name> {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
return defineModule({
|
|
19
|
+
name: definition.name,
|
|
20
|
+
variables: ["symbol", ...definition.variables],
|
|
21
|
+
defaults: {
|
|
22
|
+
format: definition.format,
|
|
23
|
+
symbol: definition.symbol,
|
|
24
|
+
style: definition.style,
|
|
25
|
+
disabled: false,
|
|
26
|
+
},
|
|
27
|
+
options: detectionOptions,
|
|
28
|
+
values: (context) => workspaceModuleValues(definition.name, context),
|
|
29
|
+
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export const nodejsModule = languageModule({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
name: "nodejs",
|
|
34
|
+
variables: ["version", "engines_version"],
|
|
35
|
+
format: "via [$symbol($version )]($style)",
|
|
36
|
+
symbol: " ",
|
|
37
|
+
style: "bold green",
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
export const pythonModule = languageModule({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
name: "python",
|
|
42
|
+
variables: ["version", "virtualenv", "pyenv_prefix"],
|
|
43
|
+
format: "via [$symbol$pyenv_prefix($version )(\\($virtualenv\\) )]($style)",
|
|
44
|
+
symbol: " ",
|
|
45
|
+
style: "yellow bold",
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
export const rustModule = languageModule({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
name: "rust",
|
|
50
|
+
variables: ["version", "numver", "toolchain"],
|
|
51
|
+
format: "via [$symbol($version )]($style)",
|
|
52
|
+
symbol: " ",
|
|
53
|
+
style: "bold red",
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
export const golangModule = languageModule({
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
name: "golang",
|
|
58
|
+
variables: ["version", "mod_version"],
|
|
59
|
+
format: "via [$symbol($version )]($style)",
|
|
60
|
+
symbol: " ",
|
|
61
|
+
style: "bold cyan",
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
export const bunModule = languageModule({
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
name: "bun",
|
|
66
|
+
variables: ["version"],
|
|
67
|
+
format: "via [$symbol($version )]($style)",
|
|
68
|
+
symbol: "🍞 ",
|
|
69
|
+
style: "bold red",
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
export const denoModule = languageModule({
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
name: "deno",
|
|
74
|
+
variables: ["version"],
|
|
75
|
+
format: "via [$symbol($version )]($style)",
|
|
76
|
+
symbol: "🦕 ",
|
|
77
|
+
style: "green bold",
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
export const languageModules = [
|
|
81
|
-
nodejsModule,
|
|
82
|
-
pythonModule,
|
|
83
|
-
rustModule,
|
|
84
|
-
golangModule,
|
|
85
|
-
bunModule,
|
|
86
|
-
denoModule,
|
|
87
|
-
] as const;
|
|
80
|
+
export const languageModules = [nodejsModule, pythonModule, rustModule, golangModule, bunModule, denoModule] as const;
|
package/src/modules/model.ts
CHANGED
|
@@ -6,80 +6,70 @@ type TruncationDirection = (typeof TRUNCATION_DIRECTIONS)[number];
|
|
|
6
6
|
const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
7
7
|
|
|
8
8
|
export const modelModule = defineModule({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
: undefined;
|
|
43
|
-
return {
|
|
44
|
-
model: truncateModel(alias ?? shortenModel(runtime.model.id), length, symbol, direction),
|
|
45
|
-
};
|
|
46
|
-
},
|
|
9
|
+
name: "model",
|
|
10
|
+
variables: ["symbol", "model"],
|
|
11
|
+
defaults: {
|
|
12
|
+
format: "[$symbol $model ]($style)",
|
|
13
|
+
symbol: "🤖",
|
|
14
|
+
style: "bold blue",
|
|
15
|
+
disabled: false,
|
|
16
|
+
},
|
|
17
|
+
options: {
|
|
18
|
+
truncation_length: { kind: "integer", default: 0, minimum: 0, maximum: 1000 },
|
|
19
|
+
truncation_symbol: { kind: "string", default: "…" },
|
|
20
|
+
truncation_direction: {
|
|
21
|
+
kind: "string-enum",
|
|
22
|
+
default: "end",
|
|
23
|
+
values: TRUNCATION_DIRECTIONS,
|
|
24
|
+
},
|
|
25
|
+
model_aliases: { kind: "string-map", default: {} },
|
|
26
|
+
},
|
|
27
|
+
values: ({ runtime, options }) => {
|
|
28
|
+
if (!runtime.model) return undefined;
|
|
29
|
+
const length = typeof options.truncation_length === "number" ? options.truncation_length : 0;
|
|
30
|
+
const symbol = typeof options.truncation_symbol === "string" ? options.truncation_symbol : "…";
|
|
31
|
+
const direction = isTruncationDirection(options.truncation_direction) ? options.truncation_direction : "end";
|
|
32
|
+
const aliases = options.model_aliases;
|
|
33
|
+
const aliasMap =
|
|
34
|
+
aliases && typeof aliases === "object" && !Array.isArray(aliases)
|
|
35
|
+
? (aliases as Readonly<Record<string, string>>)
|
|
36
|
+
: undefined;
|
|
37
|
+
const alias = aliasMap && Object.hasOwn(aliasMap, runtime.model.id) ? aliasMap[runtime.model.id] : undefined;
|
|
38
|
+
return {
|
|
39
|
+
model: truncateModel(alias ?? shortenModel(runtime.model.id), length, symbol, direction),
|
|
40
|
+
};
|
|
41
|
+
},
|
|
47
42
|
});
|
|
48
43
|
|
|
49
|
-
export function truncateModel(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const safeModel = sanitizeTerminalText(model);
|
|
56
|
-
if (length === 0) return safeModel;
|
|
57
|
-
const graphemes = [...graphemeSegmenter.segment(safeModel)].map(({ segment }) => segment);
|
|
58
|
-
if (graphemes.length <= length) return safeModel;
|
|
59
|
-
const safeSymbol = sanitizeTerminalText(symbol);
|
|
44
|
+
export function truncateModel(model: string, length: number, symbol: string, direction: TruncationDirection): string {
|
|
45
|
+
const safeModel = sanitizeTerminalText(model);
|
|
46
|
+
if (length === 0) return safeModel;
|
|
47
|
+
const graphemes = [...graphemeSegmenter.segment(safeModel)].map(({ segment }) => segment);
|
|
48
|
+
if (graphemes.length <= length) return safeModel;
|
|
49
|
+
const safeSymbol = sanitizeTerminalText(symbol);
|
|
60
50
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
51
|
+
switch (direction) {
|
|
52
|
+
case "start":
|
|
53
|
+
return `${safeSymbol}${graphemes.slice(-length).join("")}`;
|
|
54
|
+
case "middle": {
|
|
55
|
+
const headLength = Math.ceil(length / 2);
|
|
56
|
+
const tailLength = Math.floor(length / 2);
|
|
57
|
+
const tail = tailLength > 0 ? graphemes.slice(-tailLength).join("") : "";
|
|
58
|
+
return `${graphemes.slice(0, headLength).join("")}${safeSymbol}${tail}`;
|
|
59
|
+
}
|
|
60
|
+
case "end":
|
|
61
|
+
return `${graphemes.slice(0, length).join("")}${safeSymbol}`;
|
|
62
|
+
}
|
|
73
63
|
}
|
|
74
64
|
|
|
75
65
|
function isTruncationDirection(value: unknown): value is TruncationDirection {
|
|
76
|
-
|
|
66
|
+
return TRUNCATION_DIRECTIONS.includes(value as TruncationDirection);
|
|
77
67
|
}
|
|
78
68
|
|
|
79
69
|
export function shortenModel(model: string): string {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
return model
|
|
71
|
+
.replace(/^claude-/u, "")
|
|
72
|
+
.replace(/^gpt-/u, "gpt ")
|
|
73
|
+
.replace(/-20\d{6}$/u, "")
|
|
74
|
+
.replace(/-latest$/u, "");
|
|
85
75
|
}
|
package/src/modules/package.ts
CHANGED
|
@@ -2,16 +2,16 @@ import { defineModule } from "./types.js";
|
|
|
2
2
|
import { workspaceModuleValues } from "./workspace-helpers.js";
|
|
3
3
|
|
|
4
4
|
export const packageModule = defineModule({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
name: "package",
|
|
6
|
+
variables: ["symbol", "version", "source"],
|
|
7
|
+
defaults: {
|
|
8
|
+
format: "via [$symbol$version]($style) ",
|
|
9
|
+
symbol: "📦 ",
|
|
10
|
+
style: "bold 208",
|
|
11
|
+
disabled: false,
|
|
12
|
+
},
|
|
13
|
+
options: {
|
|
14
|
+
version_format: { kind: "string", default: "v$raw" },
|
|
15
|
+
},
|
|
16
|
+
values: (context) => workspaceModuleValues("package", context),
|
|
17
17
|
});
|
package/src/modules/provider.ts
CHANGED
|
@@ -4,28 +4,26 @@ import { defineModule } from "./types.js";
|
|
|
4
4
|
const PROVIDER_ALIASES_KEY = "provider_aliases";
|
|
5
5
|
|
|
6
6
|
export const providerModule = defineModule({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return { provider: sanitizeTerminalText(alias ?? runtime.model.provider) };
|
|
30
|
-
},
|
|
7
|
+
name: "provider",
|
|
8
|
+
variables: ["symbol", "provider"],
|
|
9
|
+
defaults: {
|
|
10
|
+
format: "[$symbol $provider ]($style)",
|
|
11
|
+
symbol: "🔌",
|
|
12
|
+
style: "bold blue",
|
|
13
|
+
disabled: false,
|
|
14
|
+
},
|
|
15
|
+
options: {
|
|
16
|
+
[PROVIDER_ALIASES_KEY]: { kind: "string-map", default: {} },
|
|
17
|
+
},
|
|
18
|
+
values: ({ runtime, options }) => {
|
|
19
|
+
if (!runtime.model) return undefined;
|
|
20
|
+
const aliases = options[PROVIDER_ALIASES_KEY];
|
|
21
|
+
const aliasMap =
|
|
22
|
+
aliases && typeof aliases === "object" && !Array.isArray(aliases)
|
|
23
|
+
? (aliases as Readonly<Record<string, string>>)
|
|
24
|
+
: undefined;
|
|
25
|
+
const alias =
|
|
26
|
+
aliasMap && Object.hasOwn(aliasMap, runtime.model.provider) ? aliasMap[runtime.model.provider] : undefined;
|
|
27
|
+
return { provider: sanitizeTerminalText(alias ?? runtime.model.provider) };
|
|
28
|
+
},
|
|
31
29
|
});
|
package/src/modules/render.ts
CHANGED
|
@@ -1,167 +1,151 @@
|
|
|
1
1
|
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
2
2
|
import { activePalette, type ModuleConfig, type StarshipConfig } from "../config.js";
|
|
3
3
|
import { type FormatValue, formatVariables, renderFormat } from "../format/formatter.js";
|
|
4
|
-
import {
|
|
5
|
-
isFillChunk,
|
|
6
|
-
type LayoutChunk,
|
|
7
|
-
renderChunksToAnsi,
|
|
8
|
-
type StyledChunk,
|
|
9
|
-
} from "../format/style.js";
|
|
4
|
+
import { isFillChunk, type LayoutChunk, renderChunksToAnsi, type StyledChunk } from "../format/style.js";
|
|
10
5
|
import { MODULE_DEFINITIONS, MODULE_NAMES, type ModuleName } from "./catalog.js";
|
|
11
6
|
import type { ModuleValueContext, RenderedStatusline, StarshipRuntimeSnapshot } from "./types.js";
|
|
12
7
|
|
|
13
8
|
export function renderStatusline(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
config: StarshipConfig,
|
|
10
|
+
runtime: StarshipRuntimeSnapshot,
|
|
11
|
+
width = 80,
|
|
12
|
+
trueColor = true,
|
|
18
13
|
): RenderedStatusline<ModuleName> {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
definition.layout === "fill" && !module.disabled
|
|
52
|
-
? [{ type: "fill", pattern: rendered }]
|
|
53
|
-
: rendered;
|
|
54
|
-
}
|
|
14
|
+
const palette = activePalette(config);
|
|
15
|
+
const modules = {} as Record<ModuleName, StyledChunk[]>;
|
|
16
|
+
const layoutModules = {} as Record<ModuleName, LayoutChunk[]>;
|
|
17
|
+
for (const name of MODULE_NAMES) {
|
|
18
|
+
modules[name] = [];
|
|
19
|
+
layoutModules[name] = [];
|
|
20
|
+
}
|
|
21
|
+
for (const definition of MODULE_DEFINITIONS) {
|
|
22
|
+
const name = definition.name;
|
|
23
|
+
const module = config.modules[name];
|
|
24
|
+
const values = definition.values(valueContext(config, name, runtime));
|
|
25
|
+
if (!values) continue;
|
|
26
|
+
const styleVariables = definition.resolveStyleVariables
|
|
27
|
+
? definition.resolveStyleVariables({
|
|
28
|
+
runtime,
|
|
29
|
+
values,
|
|
30
|
+
style: module.style,
|
|
31
|
+
styles: module.styles,
|
|
32
|
+
display: module.display,
|
|
33
|
+
})
|
|
34
|
+
: { style: module.style };
|
|
35
|
+
if (!styleVariables) continue;
|
|
36
|
+
const contentValues = Object.fromEntries(
|
|
37
|
+
definition.variables.flatMap((variable) =>
|
|
38
|
+
variable !== "symbol" && Object.hasOwn(values, variable) ? [[variable, values[variable]]] : [],
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
const rendered = renderModule(module, contentValues, styleVariables, palette);
|
|
42
|
+
modules[name] = rendered;
|
|
43
|
+
layoutModules[name] =
|
|
44
|
+
definition.layout === "fill" && !module.disabled ? [{ type: "fill", pattern: rendered }] : rendered;
|
|
45
|
+
}
|
|
55
46
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
47
|
+
const explicitModules = formatVariables(config.formatAst);
|
|
48
|
+
const all = MODULE_NAMES.flatMap((name) =>
|
|
49
|
+
explicitModules.has(name) || config.modules[name].disabled ? [] : layoutModules[name],
|
|
50
|
+
);
|
|
51
|
+
const rootVariables: Record<string, FormatValue> = { all };
|
|
52
|
+
for (const name of MODULE_NAMES) rootVariables[name] = layoutModules[name];
|
|
53
|
+
const layout = renderFormat(config.formatAst, { variables: rootVariables, palette });
|
|
54
|
+
const chunks = resolveFillLayout(layout, width);
|
|
55
|
+
return {
|
|
56
|
+
ansi: renderChunksToAnsi(chunks, trueColor),
|
|
57
|
+
chunks,
|
|
58
|
+
modules,
|
|
59
|
+
};
|
|
69
60
|
}
|
|
70
61
|
|
|
71
|
-
function valueContext(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
symbol: config.modules[name].symbol,
|
|
79
|
-
options: config.modules[name].options,
|
|
80
|
-
extensionStatus: config.extensionStatus,
|
|
81
|
-
};
|
|
62
|
+
function valueContext(config: StarshipConfig, name: ModuleName, runtime: StarshipRuntimeSnapshot): ModuleValueContext {
|
|
63
|
+
return {
|
|
64
|
+
runtime,
|
|
65
|
+
symbol: config.modules[name].symbol,
|
|
66
|
+
options: config.modules[name].options,
|
|
67
|
+
extensionStatus: config.extensionStatus,
|
|
68
|
+
};
|
|
82
69
|
}
|
|
83
70
|
|
|
84
71
|
function renderModule(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
72
|
+
module: ModuleConfig,
|
|
73
|
+
values: Readonly<Record<string, FormatValue>>,
|
|
74
|
+
styleVariables: Readonly<Record<string, string>>,
|
|
75
|
+
palette: Readonly<Record<string, string>>,
|
|
89
76
|
): StyledChunk[] {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
77
|
+
if (module.disabled) return [];
|
|
78
|
+
return renderFormat(module.formatAst, {
|
|
79
|
+
variables: { symbol: module.symbol, ...values },
|
|
80
|
+
styleVariables,
|
|
81
|
+
palette,
|
|
82
|
+
}).filter((chunk): chunk is StyledChunk => !isFillChunk(chunk));
|
|
96
83
|
}
|
|
97
84
|
|
|
98
|
-
export function reachableModuleRequirements(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
return requirements;
|
|
85
|
+
export function reachableModuleRequirements(config: StarshipConfig): ReadonlyMap<ModuleName, ReadonlySet<string>> {
|
|
86
|
+
const rootVariables = formatVariables(config.formatAst);
|
|
87
|
+
const includeAll = rootVariables.has("all");
|
|
88
|
+
const requirements = new Map<ModuleName, ReadonlySet<string>>();
|
|
89
|
+
for (const definition of MODULE_DEFINITIONS) {
|
|
90
|
+
if (config.modules[definition.name].disabled) continue;
|
|
91
|
+
if (!includeAll && !rootVariables.has(definition.name)) continue;
|
|
92
|
+
requirements.set(definition.name, formatVariables(config.modules[definition.name].formatAst));
|
|
93
|
+
}
|
|
94
|
+
return requirements;
|
|
110
95
|
}
|
|
111
96
|
|
|
112
97
|
function resolveFillLayout(layout: readonly LayoutChunk[], width: number): StyledChunk[] {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return resolved;
|
|
98
|
+
const lines = splitLogicalLines(layout);
|
|
99
|
+
const resolved: StyledChunk[] = [];
|
|
100
|
+
for (const [lineIndex, line] of lines.entries()) {
|
|
101
|
+
const fills = line.filter(isFillChunk);
|
|
102
|
+
const fixedWidth = line.reduce(
|
|
103
|
+
(total, chunk) => total + (isFillChunk(chunk) ? 0 : visibleWidth(renderChunksToAnsi([chunk]))),
|
|
104
|
+
0,
|
|
105
|
+
);
|
|
106
|
+
const remaining = Math.max(0, width - fixedWidth);
|
|
107
|
+
const base = fills.length > 0 ? Math.floor(remaining / fills.length) : 0;
|
|
108
|
+
let remainder = fills.length > 0 ? remaining % fills.length : 0;
|
|
109
|
+
for (const chunk of line) {
|
|
110
|
+
if (!isFillChunk(chunk)) {
|
|
111
|
+
resolved.push(chunk);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const allocation = base + (remainder > 0 ? 1 : 0);
|
|
115
|
+
if (remainder > 0) remainder -= 1;
|
|
116
|
+
resolved.push(...expandFill(chunk.pattern, allocation));
|
|
117
|
+
}
|
|
118
|
+
if (lineIndex < lines.length - 1) resolved.push({ text: "\n" });
|
|
119
|
+
}
|
|
120
|
+
return resolved;
|
|
137
121
|
}
|
|
138
122
|
|
|
139
123
|
function splitLogicalLines(layout: readonly LayoutChunk[]): LayoutChunk[][] {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
124
|
+
const lines: LayoutChunk[][] = [[]];
|
|
125
|
+
for (const chunk of layout) {
|
|
126
|
+
if (isFillChunk(chunk)) {
|
|
127
|
+
lines.at(-1)?.push(chunk);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const parts = chunk.text.split("\n");
|
|
131
|
+
for (const [index, text] of parts.entries()) {
|
|
132
|
+
if (text) lines.at(-1)?.push({ ...chunk, text });
|
|
133
|
+
if (index < parts.length - 1) lines.push([]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return lines;
|
|
153
137
|
}
|
|
154
138
|
|
|
155
139
|
function expandFill(pattern: readonly StyledChunk[], width: number): StyledChunk[] {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
140
|
+
if (width <= 0) return [];
|
|
141
|
+
const patternWidth = visibleWidth(renderChunksToAnsi(pattern));
|
|
142
|
+
if (patternWidth <= 0) return [{ text: " ".repeat(width), style: pattern[0]?.style }];
|
|
143
|
+
const repetitions = Math.floor(width / patternWidth);
|
|
144
|
+
const result: StyledChunk[] = [];
|
|
145
|
+
for (let index = 0; index < repetitions; index += 1) {
|
|
146
|
+
result.push(...pattern.map((chunk) => ({ ...chunk })));
|
|
147
|
+
}
|
|
148
|
+
const remainder = width - repetitions * patternWidth;
|
|
149
|
+
if (remainder > 0) result.push({ text: " ".repeat(remainder), style: pattern.at(-1)?.style });
|
|
150
|
+
return result;
|
|
167
151
|
}
|