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