@narumitw/pi-starship 0.57.0 → 0.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -171,6 +171,7 @@ style_root = "red bold"
171
171
  [extension_status]
172
172
  format = "([$statuses ]($style))"
173
173
  icons = { "foo:*" = "🧪", "third_party/key" = "◎", fallback = "•" }
174
+ styles = { "foo:*" = "bold green", "foo:error" = "bold red", fallback = "dimmed white" }
174
175
  ```
175
176
 
176
177
  Every module table supports `format`, `symbol`, and `disabled`.
@@ -185,6 +186,8 @@ A leading `!` is supported by language detection arrays and rejects a matching p
185
186
  Icon matching uses the exact key, the longest `:*` wildcard, a leading status emoji, then `fallback`/`🔌`.
186
187
  An empty configured icon suppresses only the icon.
187
188
  `foo:*` matches `foo:server` but not `foo`, `foobar`, or `foo/server`.
189
+ `[extension_status].styles` applies a Starship style to each complete status (icon and text) by exact raw key, then longest `:*` wildcard, then optional `fallback`; unmatched statuses inherit the module's `style`.
190
+ Separators retain the module style. An explicit `none` style removes the inherited module style for that status.
188
191
 
189
192
  Pi does not expose status ownership, so exact raw keys are the reliable third-party contract.
190
193
  pi-starship does not inspect installed packages, infer aliases, assign known-extension icons, or bridge compatibility keys.
@@ -235,8 +238,9 @@ Unknown display fields warn.
235
238
  Invalid display entries are discarded independently.
236
239
  When no valid entries remain, the complete module display default is restored.
237
240
 
238
- `extension_status` additionally accepts `separator`, `max_statuses`, and `icons`.
239
- `separator` is a string, `max_statuses` is an integer from 0 through 100, and `icons` is a string-to-string table.
241
+ `extension_status` additionally accepts `separator`, `max_statuses`, `icons`, and `styles`.
242
+ `separator` is a string, `max_statuses` is an integer from 0 through 100, `icons` is a string-to-string table, and `styles` maps raw status keys to valid Starship style strings.
243
+ Invalid `styles` entries warn and are ignored independently; a non-table value warns and uses an empty table.
240
244
 
241
245
  ### Module option types
242
246
 
@@ -998,3 +998,4 @@ Additional options:
998
998
  | `separator` | string | `" • "` | May be empty. Text inserted between rendered extension statuses. |
999
999
  | `max_statuses` | integer | `5` | Inclusive range 0 through 100. Maximum number of extension statuses rendered; zero hides all status values. |
1000
1000
  | `icons` | string-to-string table | `{}` | Keys and values are strings. Exact status-key and explicit `namespace:*` icon mappings, plus optional `fallback`. |
1001
+ | `styles` | string-to-style table | `{}` | Valid Starship style strings for exact raw status keys or explicit `namespace:*` mappings, plus optional `fallback`. Unmatched statuses inherit the module style. |
package/src/config.ts CHANGED
@@ -30,6 +30,7 @@ export interface ExtensionStatusConfig {
30
30
  separator: string;
31
31
  maxStatuses: number;
32
32
  icons: Record<string, string>;
33
+ styles: Record<string, string>;
33
34
  }
34
35
 
35
36
  export interface StarshipConfig {
@@ -91,7 +92,7 @@ export const BUILT_IN_CONFIG: StarshipConfig = {
91
92
  palette: undefined,
92
93
  palettes: {},
93
94
  modules: BUILT_IN_MODULES,
94
- extensionStatus: { separator: " • ", maxStatuses: 5, icons: {} },
95
+ extensionStatus: { separator: " • ", maxStatuses: 5, icons: {}, styles: {} },
95
96
  };
96
97
 
97
98
  export const BUILT_IN_EXAMPLE = `# Native Pi modules with Starship-compatible format and style syntax.\n${BUILT_IN_FORMAT_DOCUMENT}\n`;
@@ -271,6 +272,7 @@ function normalizeModule(
271
272
  known.add("separator");
272
273
  known.add("max_statuses");
273
274
  known.add("icons");
275
+ known.add("styles");
274
276
  }
275
277
  for (const key of Object.keys(value)) {
276
278
  if (!known.has(key)) diagnostics.push(unknownDiagnostic(`${name}.${key}`));
@@ -370,6 +372,20 @@ function normalizeModule(
370
372
  );
371
373
  }
372
374
  }
375
+ if (value.styles !== undefined) {
376
+ if (!isRecord(value.styles)) diagnostics.push(typeDiagnostic("extension_status.styles", "table"));
377
+ else {
378
+ config.extensionStatus.styles = Object.fromEntries(
379
+ Object.entries(value.styles).flatMap(([key, style]) => {
380
+ if (typeof style === "string" && isValidStyle(style, activePalette(config))) return [[key, style]];
381
+ diagnostics.push(
382
+ diagnostic("warning", `extension_status.styles.${key}`, "Expected a valid Starship style string; ignored"),
383
+ );
384
+ return [];
385
+ }),
386
+ );
387
+ }
388
+ }
373
389
  }
374
390
 
375
391
  interface AtomicFileSystem {
@@ -499,6 +515,7 @@ function cloneBuiltInConfig(): StarshipConfig {
499
515
  extensionStatus: {
500
516
  ...BUILT_IN_CONFIG.extensionStatus,
501
517
  icons: { ...BUILT_IN_CONFIG.extensionStatus.icons },
518
+ styles: { ...BUILT_IN_CONFIG.extensionStatus.styles },
502
519
  },
503
520
  };
504
521
  }
@@ -39,6 +39,7 @@ export function projectEffectiveConfig(config: StarshipConfig): TomlTable {
39
39
  table.separator = config.extensionStatus.separator;
40
40
  table.max_statuses = config.extensionStatus.maxStatuses;
41
41
  table.icons = sortedRecord(config.extensionStatus.icons);
42
+ table.styles = sortedRecord(config.extensionStatus.styles);
42
43
  }
43
44
  projected[definition.name] = table;
44
45
  }
@@ -1,3 +1,4 @@
1
+ import { parseStyle } from "../format/style.js";
1
2
  import { defineModule } from "./types.js";
2
3
 
3
4
  export const extensionStatusModule = defineModule({
@@ -9,16 +10,25 @@ export const extensionStatusModule = defineModule({
9
10
  style: "dimmed white",
10
11
  disabled: false,
11
12
  },
12
- values: ({ runtime, extensionStatus }) => {
13
+ values: ({ runtime, extensionStatus, palette }) => {
13
14
  const statuses = [...runtime.extensionStatuses.entries()]
14
15
  .filter(([key, value]) => key !== "starship" && value.trim())
15
- .map(([key, value]) => formatExtensionStatus(key, value, extensionStatus.icons))
16
- .slice(0, extensionStatus.maxStatuses);
16
+ .slice(0, extensionStatus.maxStatuses)
17
+ .map(([key, value]) => ({ key, text: formatExtensionStatus(key, value, extensionStatus.icons) }));
17
18
  if (statuses.length === 0) return undefined;
18
- return {
19
- statuses: statuses.join(extensionStatus.separator),
20
- count: `${statuses.length}`,
21
- };
19
+ const { separator, styles } = extensionStatus;
20
+ const content =
21
+ Object.keys(styles).length === 0
22
+ ? statuses.map(({ text }) => text).join(separator)
23
+ : statuses.flatMap(({ key, text }, index) => {
24
+ const configured = configuredStatusValue(key, styles);
25
+ const style = configured ?? (Object.hasOwn(styles, "fallback") ? styles.fallback : undefined);
26
+ return [
27
+ ...(index > 0 ? [{ text: separator }] : []),
28
+ { text, style: style === undefined ? undefined : (parseStyle(style, palette) ?? {}) },
29
+ ];
30
+ });
31
+ return { statuses: content, count: `${statuses.length}` };
22
32
  },
23
33
  });
24
34
 
@@ -38,22 +48,22 @@ function extensionStatusIcon(
38
48
  leadingIcon: string | undefined,
39
49
  configuredIcons: Readonly<Record<string, string>>,
40
50
  ): string {
41
- if (Object.hasOwn(configuredIcons, key)) return configuredIcons[key] ?? "";
42
- const namespaceIcon = configuredNamespaceIcon(key, configuredIcons);
43
- if (namespaceIcon !== undefined) return namespaceIcon;
44
- const fallbackIcon = Object.hasOwn(configuredIcons, "fallback") ? configuredIcons.fallback : undefined;
45
- return leadingIcon ?? fallbackIcon ?? "🔌";
51
+ const configured = configuredStatusValue(key, configuredIcons);
52
+ if (configured !== undefined) return configured;
53
+ const fallback = Object.hasOwn(configuredIcons, "fallback") ? configuredIcons.fallback : undefined;
54
+ return leadingIcon ?? fallback ?? "🔌";
46
55
  }
47
56
 
48
- function configuredNamespaceIcon(key: string, configuredIcons: Readonly<Record<string, string>>): string | undefined {
49
- let match: { baseLength: number; icon: string } | undefined;
50
- for (const [selector, icon] of Object.entries(configuredIcons)) {
57
+ function configuredStatusValue(key: string, configured: Readonly<Record<string, string>>): string | undefined {
58
+ if (Object.hasOwn(configured, key)) return configured[key];
59
+ let match: { baseLength: number; value: string } | undefined;
60
+ for (const [selector, value] of Object.entries(configured)) {
51
61
  if (!selector.endsWith(":*")) continue;
52
62
  const base = selector.slice(0, -2);
53
63
  if (!base || !key.startsWith(`${base}:`)) continue;
54
- if (!match || base.length > match.baseLength) match = { baseLength: base.length, icon };
64
+ if (!match || base.length > match.baseLength) match = { baseLength: base.length, value };
55
65
  }
56
- return match?.icon;
66
+ return match?.value;
57
67
  }
58
68
 
59
69
  function splitExtensionStatusIcon(value: string): { icon?: string; text: string } {
@@ -1,7 +1,13 @@
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 { isFillChunk, type LayoutChunk, renderChunksToAnsi, type StyledChunk } from "../format/style.js";
4
+ import {
5
+ type ColorPalette,
6
+ isFillChunk,
7
+ type LayoutChunk,
8
+ renderChunksToAnsi,
9
+ type StyledChunk,
10
+ } from "../format/style.js";
5
11
  import { MODULE_DEFINITIONS, MODULE_NAMES, type ModuleName } from "./catalog.js";
6
12
  import { resolveStyleRule } from "./style-rules.js";
7
13
  import type { ModuleStyleContext, ModuleValueContext, RenderedStatusline, StarshipRuntimeSnapshot } from "./types.js";
@@ -22,11 +28,10 @@ export function renderStatusline(
22
28
  for (const definition of MODULE_DEFINITIONS) {
23
29
  const name = definition.name;
24
30
  const module = config.modules[name];
25
- const values = definition.values(valueContext(config, name, runtime));
31
+ const values = definition.values(valueContext(config, name, runtime, palette));
26
32
  if (!values) continue;
27
33
  const styleContext: ModuleStyleContext = {
28
34
  runtime,
29
- values,
30
35
  style: module.style,
31
36
  styles: module.styles,
32
37
  display: module.display,
@@ -39,7 +44,7 @@ export function renderStatusline(
39
44
  ? resolveStyleRule(module.styleRules, definition.styleRuleSelectors, styleContext)
40
45
  : undefined;
41
46
  const styleVariables = ruleStyle === undefined ? baseStyleVariables : { ...baseStyleVariables, style: ruleStyle };
42
- const contentValues = Object.fromEntries(
47
+ const contentValues: Record<string, FormatValue> = Object.fromEntries(
43
48
  definition.variables.flatMap((variable) =>
44
49
  variable !== "symbol" && Object.hasOwn(values, variable) ? [[variable, values[variable]]] : [],
45
50
  ),
@@ -65,9 +70,15 @@ export function renderStatusline(
65
70
  };
66
71
  }
67
72
 
68
- function valueContext(config: StarshipConfig, name: ModuleName, runtime: StarshipRuntimeSnapshot): ModuleValueContext {
73
+ function valueContext(
74
+ config: StarshipConfig,
75
+ name: ModuleName,
76
+ runtime: StarshipRuntimeSnapshot,
77
+ palette: ColorPalette,
78
+ ): ModuleValueContext {
69
79
  return {
70
80
  runtime,
81
+ palette,
71
82
  symbol: config.modules[name].symbol,
72
83
  options: config.modules[name].options,
73
84
  extensionStatus: config.extensionStatus,
@@ -1,5 +1,6 @@
1
1
  import type { UIPromptKind } from "@earendil-works/pi-coding-agent";
2
- import type { StyledChunk } from "../format/style.js";
2
+ import type { FormatValue } from "../format/formatter.js";
3
+ import type { ColorPalette, StyledChunk } from "../format/style.js";
3
4
 
4
5
  export interface GitBranchSnapshot {
5
6
  name: string;
@@ -120,12 +121,14 @@ export interface ExtensionStatusPresentation {
120
121
  separator: string;
121
122
  maxStatuses: number;
122
123
  icons: Readonly<Record<string, string>>;
124
+ styles: Readonly<Record<string, string>>;
123
125
  }
124
126
 
125
127
  export type ModuleOptionValue = string | boolean | number | readonly string[] | Readonly<Record<string, string>>;
126
128
 
127
129
  export interface ModuleValueContext {
128
130
  runtime: StarshipRuntimeSnapshot;
131
+ palette: ColorPalette;
129
132
  symbol: string;
130
133
  options: Readonly<Record<string, ModuleOptionValue>>;
131
134
  extensionStatus: ExtensionStatusPresentation;
@@ -159,7 +162,6 @@ export interface ModuleDefaults {
159
162
 
160
163
  export interface ModuleStyleContext {
161
164
  runtime: StarshipRuntimeSnapshot;
162
- values: Readonly<Record<string, string>>;
163
165
  style: string;
164
166
  styles: Readonly<Record<string, string>>;
165
167
  display: readonly ModuleDisplayConfig[];
@@ -179,7 +181,7 @@ export interface ModuleDefinition<Name extends string> {
179
181
  resolveStyleVariables?(context: ModuleStyleContext): Readonly<Record<string, string>> | undefined;
180
182
  options?: Readonly<Record<string, ModuleOptionSchema>>;
181
183
  layout?: "fill";
182
- values(context: ModuleValueContext): Record<string, string> | undefined;
184
+ values(context: ModuleValueContext): Record<string, FormatValue> | undefined;
183
185
  }
184
186
 
185
187
  export function defineModule<const Name extends string>(definition: ModuleDefinition<Name>): ModuleDefinition<Name> {