pi-powerline-footer 0.2.12 → 0.2.13
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/CHANGELOG.md +15 -0
- package/README.md +41 -0
- package/index.ts +14 -10
- package/package.json +2 -1
- package/presets.ts +32 -1
- package/segments.ts +35 -37
- package/theme.example.json +19 -0
- package/theme.ts +171 -0
- package/types.ts +32 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.2.13] - 2026-01-27
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Theme system** — Colors now integrate with pi's theme system instead of hardcoded values
|
|
9
|
+
- Each preset defines its own color scheme with semantic color names
|
|
10
|
+
- Optional `theme.json` file for user customization (power user feature)
|
|
11
|
+
- Colors can be theme names (`accent`, `primary`, `muted`) or hex values (`#ff5500`)
|
|
12
|
+
- Added `theme.example.json` documenting all available color options
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- Segments now use pi's `Theme` object for color rendering
|
|
16
|
+
- Removed hardcoded ANSI color codes in favor of theme-based colors
|
|
17
|
+
- Presets include both layout AND color scheme for cohesive looks
|
|
18
|
+
- Simplified thinking level colors to use semantic `thinking` color (rainbow preserved for high/xhigh)
|
|
19
|
+
|
|
5
20
|
## [0.2.12] - 2026-01-27
|
|
6
21
|
|
|
7
22
|
### Added
|
package/README.md
CHANGED
|
@@ -75,3 +75,44 @@ Configure via preset options: `path: { mode: "full" }`
|
|
|
75
75
|
## Separators
|
|
76
76
|
|
|
77
77
|
`powerline` · `powerline-thin` · `slash` · `pipe` · `dot` · `chevron` · `star` · `block` · `none` · `ascii`
|
|
78
|
+
|
|
79
|
+
## Theming
|
|
80
|
+
|
|
81
|
+
Colors are configurable via pi's theme system. Each preset defines its own color scheme, and you can override individual colors with a `theme.json` file in the extension directory.
|
|
82
|
+
|
|
83
|
+
### Default Colors
|
|
84
|
+
|
|
85
|
+
| Semantic | Theme Color | Description |
|
|
86
|
+
|----------|-------------|-------------|
|
|
87
|
+
| `pi` | `accent` | Pi icon |
|
|
88
|
+
| `model` | `primary` | Model name |
|
|
89
|
+
| `path` | `muted` | Directory path |
|
|
90
|
+
| `gitClean` | `success` | Git branch (clean) |
|
|
91
|
+
| `gitDirty` | `warning` | Git branch (dirty) |
|
|
92
|
+
| `thinking` | `muted` | Thinking level |
|
|
93
|
+
| `context` | `dim` | Context usage |
|
|
94
|
+
| `contextWarn` | `warning` | Context usage >70% |
|
|
95
|
+
| `contextError` | `error` | Context usage >90% |
|
|
96
|
+
| `cost` | `primary` | Cost display |
|
|
97
|
+
| `tokens` | `muted` | Token counts |
|
|
98
|
+
|
|
99
|
+
### Custom Theme Override
|
|
100
|
+
|
|
101
|
+
Create `~/.pi/agent/extensions/powerline-footer/theme.json`:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"colors": {
|
|
106
|
+
"pi": "#ff5500",
|
|
107
|
+
"model": "accent",
|
|
108
|
+
"path": "#00afaf",
|
|
109
|
+
"gitClean": "success"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Colors can be:
|
|
115
|
+
- **Theme color names**: `accent`, `primary`, `muted`, `dim`, `text`, `success`, `warning`, `error`, `borderMuted`
|
|
116
|
+
- **Hex colors**: `#ff5500`, `#d787af`
|
|
117
|
+
|
|
118
|
+
See `theme.example.json` for all available options.
|
package/index.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import type { ExtensionAPI, ReadonlyFooterDataProvider } from "@mariozechner/pi-coding-agent";
|
|
1
|
+
import type { ExtensionAPI, ReadonlyFooterDataProvider, Theme } from "@mariozechner/pi-coding-agent";
|
|
2
2
|
import type { AssistantMessage } from "@mariozechner/pi-ai";
|
|
3
3
|
import { visibleWidth } from "@mariozechner/pi-tui";
|
|
4
4
|
import { readFileSync, existsSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
|
|
7
|
-
import type { SegmentContext, StatusLinePreset, StatusLineSegmentId } from "./types.js";
|
|
7
|
+
import type { ColorScheme, SegmentContext, StatusLinePreset, StatusLineSegmentId } from "./types.js";
|
|
8
8
|
import { getPreset, PRESETS } from "./presets.js";
|
|
9
9
|
import { getSeparator } from "./separators.js";
|
|
10
10
|
import { renderSegment } from "./segments.js";
|
|
11
11
|
import { getGitStatus, invalidateGitStatus, invalidateGitBranch } from "./git-status.js";
|
|
12
12
|
import { ansi, getFgAnsiCode } from "./colors.js";
|
|
13
13
|
import { WelcomeComponent, WelcomeHeader, discoverLoadedCounts, getRecentSessions } from "./welcome.js";
|
|
14
|
+
import { getDefaultColors } from "./theme.js";
|
|
14
15
|
|
|
15
16
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
16
17
|
// Configuration
|
|
@@ -328,8 +329,9 @@ export default function powerlineFooter(pi: ExtensionAPI) {
|
|
|
328
329
|
},
|
|
329
330
|
});
|
|
330
331
|
|
|
331
|
-
function buildSegmentContext(ctx: any, width: number): SegmentContext {
|
|
332
|
+
function buildSegmentContext(ctx: any, width: number, theme: Theme): SegmentContext {
|
|
332
333
|
const presetDef = getPreset(config.preset);
|
|
334
|
+
const colors: ColorScheme = presetDef.colors ?? getDefaultColors();
|
|
333
335
|
|
|
334
336
|
// Build usage stats and get thinking level from session
|
|
335
337
|
let input = 0, output = 0, cacheRead = 0, cacheWrite = 0, cost = 0;
|
|
@@ -387,6 +389,8 @@ export default function powerlineFooter(pi: ExtensionAPI) {
|
|
|
387
389
|
extensionStatuses: footerDataRef?.getExtensionStatuses() ?? new Map(),
|
|
388
390
|
options: presetDef.segmentOptions ?? {},
|
|
389
391
|
width,
|
|
392
|
+
theme,
|
|
393
|
+
colors,
|
|
390
394
|
};
|
|
391
395
|
}
|
|
392
396
|
|
|
@@ -394,7 +398,7 @@ export default function powerlineFooter(pi: ExtensionAPI) {
|
|
|
394
398
|
* Get cached responsive layout or compute fresh one.
|
|
395
399
|
* Layout is cached per render cycle (same width = same layout).
|
|
396
400
|
*/
|
|
397
|
-
function getResponsiveLayout(width: number): { topContent: string; secondaryContent: string } {
|
|
401
|
+
function getResponsiveLayout(width: number, theme: Theme): { topContent: string; secondaryContent: string } {
|
|
398
402
|
const now = Date.now();
|
|
399
403
|
// Cache is valid if same width and within 50ms (same render cycle)
|
|
400
404
|
if (lastLayoutResult && lastLayoutWidth === width && now - lastLayoutTimestamp < 50) {
|
|
@@ -402,7 +406,7 @@ export default function powerlineFooter(pi: ExtensionAPI) {
|
|
|
402
406
|
}
|
|
403
407
|
|
|
404
408
|
const presetDef = getPreset(config.preset);
|
|
405
|
-
const segmentCtx = buildSegmentContext(currentCtx, width);
|
|
409
|
+
const segmentCtx = buildSegmentContext(currentCtx, width, theme);
|
|
406
410
|
// Available width for top bar content (minus box corners: ╭─ and ─╮ = 4 chars)
|
|
407
411
|
const topBarAvailable = width - 4;
|
|
408
412
|
|
|
@@ -473,7 +477,7 @@ export default function powerlineFooter(pi: ExtensionAPI) {
|
|
|
473
477
|
|
|
474
478
|
// Top border: ╭─ status ────────────╮
|
|
475
479
|
// Use responsive layout - overflow goes to secondary row
|
|
476
|
-
const layout = getResponsiveLayout(width);
|
|
480
|
+
const layout = getResponsiveLayout(width, theme);
|
|
477
481
|
const statusContent = layout.topContent;
|
|
478
482
|
const statusWidth = visibleWidth(statusContent);
|
|
479
483
|
const topFillWidth = width - 4; // Reserve 4 for corners (╭─ and ─╮)
|
|
@@ -515,7 +519,7 @@ export default function powerlineFooter(pi: ExtensionAPI) {
|
|
|
515
519
|
});
|
|
516
520
|
|
|
517
521
|
// Set up footer data provider access via a minimal footer
|
|
518
|
-
ctx.ui.setFooter((tui: any,
|
|
522
|
+
ctx.ui.setFooter((tui: any, theme: Theme, footerData: ReadonlyFooterDataProvider) => {
|
|
519
523
|
footerDataRef = footerData;
|
|
520
524
|
tuiRef = tui; // Store TUI reference for re-renders on git branch changes
|
|
521
525
|
const unsub = footerData.onBranchChange(() => tui.requestRender());
|
|
@@ -529,7 +533,7 @@ export default function powerlineFooter(pi: ExtensionAPI) {
|
|
|
529
533
|
if (!currentCtx) return [];
|
|
530
534
|
|
|
531
535
|
const presetDef = getPreset(config.preset);
|
|
532
|
-
const segmentCtx = buildSegmentContext(currentCtx, width);
|
|
536
|
+
const segmentCtx = buildSegmentContext(currentCtx, width, theme);
|
|
533
537
|
const lines: string[] = [];
|
|
534
538
|
|
|
535
539
|
// During streaming, show primary status in footer (editor hidden)
|
|
@@ -573,7 +577,7 @@ export default function powerlineFooter(pi: ExtensionAPI) {
|
|
|
573
577
|
|
|
574
578
|
// Set up secondary row as a widget below editor (above sub bar)
|
|
575
579
|
// Shows overflow segments when top bar is too narrow
|
|
576
|
-
ctx.ui.setWidget("powerline-secondary", (tui: any,
|
|
580
|
+
ctx.ui.setWidget("powerline-secondary", (tui: any, theme: Theme) => {
|
|
577
581
|
return {
|
|
578
582
|
dispose() {},
|
|
579
583
|
invalidate() {},
|
|
@@ -581,7 +585,7 @@ export default function powerlineFooter(pi: ExtensionAPI) {
|
|
|
581
585
|
if (!currentCtx) return [];
|
|
582
586
|
|
|
583
587
|
// Use responsive layout - secondary row shows overflow from top bar
|
|
584
|
-
const layout = getResponsiveLayout(width);
|
|
588
|
+
const layout = getResponsiveLayout(width, theme);
|
|
585
589
|
|
|
586
590
|
// Only show secondary row if there's overflow content that fits
|
|
587
591
|
if (layout.secondaryContent) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-powerline-footer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "Powerline-style status bar extension for pi coding agent",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"*.ts",
|
|
11
11
|
"*.md",
|
|
12
|
+
"*.json",
|
|
12
13
|
"cli.js"
|
|
13
14
|
],
|
|
14
15
|
"keywords": [
|
package/presets.ts
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
|
-
import type { PresetDef, StatusLinePreset } from "./types.js";
|
|
1
|
+
import type { ColorScheme, PresetDef, StatusLinePreset } from "./types.js";
|
|
2
|
+
import { getDefaultColors } from "./theme.js";
|
|
3
|
+
|
|
4
|
+
// Get base colors from theme.ts (single source of truth)
|
|
5
|
+
const DEFAULT_COLORS: ColorScheme = getDefaultColors();
|
|
6
|
+
|
|
7
|
+
// Minimal - more muted, less colorful
|
|
8
|
+
const MINIMAL_COLORS: ColorScheme = {
|
|
9
|
+
...DEFAULT_COLORS,
|
|
10
|
+
pi: "dim",
|
|
11
|
+
model: "text",
|
|
12
|
+
path: "text",
|
|
13
|
+
git: "dim",
|
|
14
|
+
gitClean: "dim",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Nerd - vibrant colors
|
|
18
|
+
const NERD_COLORS: ColorScheme = {
|
|
19
|
+
...DEFAULT_COLORS,
|
|
20
|
+
pi: "accent",
|
|
21
|
+
model: "accent",
|
|
22
|
+
path: "success",
|
|
23
|
+
tokens: "primary",
|
|
24
|
+
cost: "warning",
|
|
25
|
+
};
|
|
2
26
|
|
|
3
27
|
export const PRESETS: Record<StatusLinePreset, PresetDef> = {
|
|
4
28
|
default: {
|
|
@@ -6,6 +30,7 @@ export const PRESETS: Record<StatusLinePreset, PresetDef> = {
|
|
|
6
30
|
rightSegments: [],
|
|
7
31
|
secondarySegments: ["extension_statuses"],
|
|
8
32
|
separator: "powerline-thin",
|
|
33
|
+
colors: DEFAULT_COLORS,
|
|
9
34
|
segmentOptions: {
|
|
10
35
|
model: { showThinkingLevel: false },
|
|
11
36
|
path: { mode: "basename" },
|
|
@@ -17,6 +42,7 @@ export const PRESETS: Record<StatusLinePreset, PresetDef> = {
|
|
|
17
42
|
leftSegments: ["path", "git"],
|
|
18
43
|
rightSegments: ["context_pct"],
|
|
19
44
|
separator: "slash",
|
|
45
|
+
colors: MINIMAL_COLORS,
|
|
20
46
|
segmentOptions: {
|
|
21
47
|
path: { mode: "basename" },
|
|
22
48
|
git: { showBranch: true, showStaged: false, showUnstaged: false, showUntracked: false },
|
|
@@ -27,6 +53,7 @@ export const PRESETS: Record<StatusLinePreset, PresetDef> = {
|
|
|
27
53
|
leftSegments: ["model", "git"],
|
|
28
54
|
rightSegments: ["cost", "context_pct"],
|
|
29
55
|
separator: "powerline-thin",
|
|
56
|
+
colors: DEFAULT_COLORS,
|
|
30
57
|
segmentOptions: {
|
|
31
58
|
model: { showThinkingLevel: false },
|
|
32
59
|
git: { showBranch: true, showStaged: true, showUnstaged: true, showUntracked: false },
|
|
@@ -37,6 +64,7 @@ export const PRESETS: Record<StatusLinePreset, PresetDef> = {
|
|
|
37
64
|
leftSegments: ["pi", "hostname", "model", "thinking", "path", "git", "subagents"],
|
|
38
65
|
rightSegments: ["token_in", "token_out", "cache_read", "cost", "context_pct", "time_spent", "time", "extension_statuses"],
|
|
39
66
|
separator: "powerline",
|
|
67
|
+
colors: DEFAULT_COLORS,
|
|
40
68
|
segmentOptions: {
|
|
41
69
|
model: { showThinkingLevel: false },
|
|
42
70
|
path: { mode: "abbreviated", maxLength: 50 },
|
|
@@ -49,6 +77,7 @@ export const PRESETS: Record<StatusLinePreset, PresetDef> = {
|
|
|
49
77
|
leftSegments: ["pi", "hostname", "model", "thinking", "path", "git", "session", "subagents"],
|
|
50
78
|
rightSegments: ["token_in", "token_out", "cache_read", "cache_write", "cost", "context_pct", "context_total", "time_spent", "time", "extension_statuses"],
|
|
51
79
|
separator: "powerline",
|
|
80
|
+
colors: NERD_COLORS,
|
|
52
81
|
segmentOptions: {
|
|
53
82
|
model: { showThinkingLevel: false },
|
|
54
83
|
path: { mode: "abbreviated", maxLength: 60 },
|
|
@@ -61,6 +90,7 @@ export const PRESETS: Record<StatusLinePreset, PresetDef> = {
|
|
|
61
90
|
leftSegments: ["model", "path", "git"],
|
|
62
91
|
rightSegments: ["token_total", "cost", "context_pct"],
|
|
63
92
|
separator: "ascii",
|
|
93
|
+
colors: MINIMAL_COLORS,
|
|
64
94
|
segmentOptions: {
|
|
65
95
|
model: { showThinkingLevel: true },
|
|
66
96
|
path: { mode: "abbreviated", maxLength: 40 },
|
|
@@ -72,6 +102,7 @@ export const PRESETS: Record<StatusLinePreset, PresetDef> = {
|
|
|
72
102
|
leftSegments: ["model", "path", "git"],
|
|
73
103
|
rightSegments: ["token_total", "cost", "context_pct"],
|
|
74
104
|
separator: "powerline-thin",
|
|
105
|
+
colors: DEFAULT_COLORS,
|
|
75
106
|
segmentOptions: {},
|
|
76
107
|
},
|
|
77
108
|
};
|
package/segments.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { hostname as osHostname } from "node:os";
|
|
2
2
|
import { basename } from "node:path";
|
|
3
|
-
import type { RenderedSegment, SegmentContext, StatusLineSegment, StatusLineSegmentId } from "./types.js";
|
|
4
|
-
import {
|
|
3
|
+
import type { RenderedSegment, SegmentContext, SemanticColor, StatusLineSegment, StatusLineSegmentId } from "./types.js";
|
|
4
|
+
import { fg, rainbow, applyColor } from "./theme.js";
|
|
5
5
|
import { getIcons, SEP_DOT, getThinkingText } from "./icons.js";
|
|
6
6
|
|
|
7
|
+
// Helper to apply semantic color from context
|
|
8
|
+
function color(ctx: SegmentContext, semantic: SemanticColor, text: string): string {
|
|
9
|
+
return fg(ctx.theme, semantic, text, ctx.colors);
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
8
13
|
// Helpers
|
|
9
14
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -36,11 +41,11 @@ function formatDuration(ms: number): string {
|
|
|
36
41
|
|
|
37
42
|
const piSegment: StatusLineSegment = {
|
|
38
43
|
id: "pi",
|
|
39
|
-
render(
|
|
44
|
+
render(ctx) {
|
|
40
45
|
const icons = getIcons();
|
|
41
46
|
if (!icons.pi) return { content: "", visible: false };
|
|
42
47
|
const content = `${icons.pi} `;
|
|
43
|
-
return { content:
|
|
48
|
+
return { content: color(ctx, "pi", content), visible: true };
|
|
44
49
|
},
|
|
45
50
|
};
|
|
46
51
|
|
|
@@ -69,7 +74,7 @@ const modelSegment: StatusLineSegment = {
|
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
76
|
|
|
72
|
-
return { content:
|
|
77
|
+
return { content: color(ctx, "model", content), visible: true };
|
|
73
78
|
},
|
|
74
79
|
};
|
|
75
80
|
|
|
@@ -107,7 +112,7 @@ const pathSegment: StatusLineSegment = {
|
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
const content = withIcon(icons.folder, pwd);
|
|
110
|
-
return { content:
|
|
115
|
+
return { content: color(ctx, "path", content), visible: true };
|
|
111
116
|
},
|
|
112
117
|
};
|
|
113
118
|
|
|
@@ -125,29 +130,32 @@ const gitSegment: StatusLineSegment = {
|
|
|
125
130
|
|
|
126
131
|
const isDirty = gitStatus && (gitStatus.staged > 0 || gitStatus.unstaged > 0 || gitStatus.untracked > 0);
|
|
127
132
|
const showBranch = opts.showBranch !== false;
|
|
133
|
+
const branchColor: SemanticColor = isDirty ? "gitDirty" : "gitClean";
|
|
128
134
|
|
|
129
|
-
// Build content
|
|
135
|
+
// Build content - color branch separately from indicators
|
|
130
136
|
let content = "";
|
|
131
137
|
if (showBranch && branch) {
|
|
132
|
-
|
|
138
|
+
// Color just the branch name (icon + branch text)
|
|
139
|
+
content = color(ctx, branchColor, withIcon(icons.branch, branch));
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
// Add status indicators
|
|
142
|
+
// Add status indicators (each with their own color, not wrapped)
|
|
136
143
|
if (gitStatus) {
|
|
137
144
|
const indicators: string[] = [];
|
|
138
145
|
if (opts.showUnstaged !== false && gitStatus.unstaged > 0) {
|
|
139
|
-
indicators.push(
|
|
146
|
+
indicators.push(applyColor(ctx.theme, "warning", `*${gitStatus.unstaged}`));
|
|
140
147
|
}
|
|
141
148
|
if (opts.showStaged !== false && gitStatus.staged > 0) {
|
|
142
|
-
indicators.push(
|
|
149
|
+
indicators.push(applyColor(ctx.theme, "success", `+${gitStatus.staged}`));
|
|
143
150
|
}
|
|
144
151
|
if (opts.showUntracked !== false && gitStatus.untracked > 0) {
|
|
145
|
-
indicators.push(
|
|
152
|
+
indicators.push(applyColor(ctx.theme, "muted", `?${gitStatus.untracked}`));
|
|
146
153
|
}
|
|
147
154
|
if (indicators.length > 0) {
|
|
148
155
|
const indicatorText = indicators.join(" ");
|
|
149
156
|
if (!content && showBranch === false) {
|
|
150
|
-
|
|
157
|
+
// No branch shown, color the git icon with branch color
|
|
158
|
+
content = color(ctx, branchColor, icons.git ? `${icons.git} ` : "") + indicatorText;
|
|
151
159
|
} else {
|
|
152
160
|
content += content ? ` ${indicatorText}` : indicatorText;
|
|
153
161
|
}
|
|
@@ -156,9 +164,7 @@ const gitSegment: StatusLineSegment = {
|
|
|
156
164
|
|
|
157
165
|
if (!content) return { content: "", visible: false };
|
|
158
166
|
|
|
159
|
-
|
|
160
|
-
const colorName = isDirty ? "gitDirty" : "gitClean";
|
|
161
|
-
return { content: fgOnly(colorName, content), visible: true };
|
|
167
|
+
return { content, visible: true };
|
|
162
168
|
},
|
|
163
169
|
};
|
|
164
170
|
|
|
@@ -184,16 +190,8 @@ const thinkingSegment: StatusLineSegment = {
|
|
|
184
190
|
return { content: rainbow(content), visible: true };
|
|
185
191
|
}
|
|
186
192
|
|
|
187
|
-
// Use
|
|
188
|
-
|
|
189
|
-
off: "thinkingOff",
|
|
190
|
-
minimal: "thinkingMinimal",
|
|
191
|
-
low: "thinkingLow",
|
|
192
|
-
medium: "thinkingMedium",
|
|
193
|
-
};
|
|
194
|
-
const color = colorMap[level] || "thinkingOff";
|
|
195
|
-
|
|
196
|
-
return { content: fgOnly(color, content), visible: true };
|
|
193
|
+
// Use thinking color for lower levels
|
|
194
|
+
return { content: color(ctx, "thinking", content), visible: true };
|
|
197
195
|
},
|
|
198
196
|
};
|
|
199
197
|
|
|
@@ -215,7 +213,7 @@ const tokenInSegment: StatusLineSegment = {
|
|
|
215
213
|
if (!input) return { content: "", visible: false };
|
|
216
214
|
|
|
217
215
|
const content = withIcon(icons.input, formatTokens(input));
|
|
218
|
-
return { content:
|
|
216
|
+
return { content: color(ctx, "tokens", content), visible: true };
|
|
219
217
|
},
|
|
220
218
|
};
|
|
221
219
|
|
|
@@ -227,7 +225,7 @@ const tokenOutSegment: StatusLineSegment = {
|
|
|
227
225
|
if (!output) return { content: "", visible: false };
|
|
228
226
|
|
|
229
227
|
const content = withIcon(icons.output, formatTokens(output));
|
|
230
|
-
return { content:
|
|
228
|
+
return { content: color(ctx, "tokens", content), visible: true };
|
|
231
229
|
},
|
|
232
230
|
};
|
|
233
231
|
|
|
@@ -240,7 +238,7 @@ const tokenTotalSegment: StatusLineSegment = {
|
|
|
240
238
|
if (!total) return { content: "", visible: false };
|
|
241
239
|
|
|
242
240
|
const content = withIcon(icons.tokens, formatTokens(total));
|
|
243
|
-
return { content:
|
|
241
|
+
return { content: color(ctx, "tokens", content), visible: true };
|
|
244
242
|
},
|
|
245
243
|
};
|
|
246
244
|
|
|
@@ -255,7 +253,7 @@ const costSegment: StatusLineSegment = {
|
|
|
255
253
|
}
|
|
256
254
|
|
|
257
255
|
const costDisplay = usingSubscription ? "(sub)" : `$${cost.toFixed(2)}`;
|
|
258
|
-
return { content:
|
|
256
|
+
return { content: color(ctx, "cost", costDisplay), visible: true };
|
|
259
257
|
},
|
|
260
258
|
};
|
|
261
259
|
|
|
@@ -269,14 +267,14 @@ const contextPctSegment: StatusLineSegment = {
|
|
|
269
267
|
const autoIcon = ctx.autoCompactEnabled && icons.auto ? ` ${icons.auto}` : "";
|
|
270
268
|
const text = `${pct.toFixed(1)}%/${formatTokens(window)}${autoIcon}`;
|
|
271
269
|
|
|
272
|
-
// Icon outside color, text inside
|
|
270
|
+
// Icon outside color, text inside - use semantic colors for thresholds
|
|
273
271
|
let content: string;
|
|
274
272
|
if (pct > 90) {
|
|
275
|
-
content = withIcon(icons.context,
|
|
273
|
+
content = withIcon(icons.context, color(ctx, "contextError", text));
|
|
276
274
|
} else if (pct > 70) {
|
|
277
|
-
content = withIcon(icons.context,
|
|
275
|
+
content = withIcon(icons.context, color(ctx, "contextWarn", text));
|
|
278
276
|
} else {
|
|
279
|
-
content = withIcon(icons.context,
|
|
277
|
+
content = withIcon(icons.context, color(ctx, "context", text));
|
|
280
278
|
}
|
|
281
279
|
|
|
282
280
|
return { content, visible: true };
|
|
@@ -291,7 +289,7 @@ const contextTotalSegment: StatusLineSegment = {
|
|
|
291
289
|
if (!window) return { content: "", visible: false };
|
|
292
290
|
|
|
293
291
|
return {
|
|
294
|
-
content:
|
|
292
|
+
content: color(ctx, "context", withIcon(icons.context, formatTokens(window))),
|
|
295
293
|
visible: true,
|
|
296
294
|
};
|
|
297
295
|
},
|
|
@@ -367,7 +365,7 @@ const cacheReadSegment: StatusLineSegment = {
|
|
|
367
365
|
// Space-separated parts
|
|
368
366
|
const parts = [icons.cache, icons.input, formatTokens(cacheRead)].filter(Boolean);
|
|
369
367
|
const content = parts.join(" ");
|
|
370
|
-
return { content:
|
|
368
|
+
return { content: color(ctx, "tokens", content), visible: true };
|
|
371
369
|
},
|
|
372
370
|
};
|
|
373
371
|
|
|
@@ -381,7 +379,7 @@ const cacheWriteSegment: StatusLineSegment = {
|
|
|
381
379
|
// Space-separated parts
|
|
382
380
|
const parts = [icons.cache, icons.output, formatTokens(cacheWrite)].filter(Boolean);
|
|
383
381
|
const content = parts.join(" ");
|
|
384
|
-
return { content:
|
|
382
|
+
return { content: color(ctx, "tokens", content), visible: true };
|
|
385
383
|
},
|
|
386
384
|
};
|
|
387
385
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"colors": {
|
|
3
|
+
"pi": "accent",
|
|
4
|
+
"model": "primary",
|
|
5
|
+
"path": "muted",
|
|
6
|
+
"git": "success",
|
|
7
|
+
"gitDirty": "warning",
|
|
8
|
+
"gitClean": "success",
|
|
9
|
+
"thinking": "muted",
|
|
10
|
+
"thinkingHigh": "accent",
|
|
11
|
+
"context": "dim",
|
|
12
|
+
"contextWarn": "warning",
|
|
13
|
+
"contextError": "error",
|
|
14
|
+
"cost": "primary",
|
|
15
|
+
"tokens": "muted",
|
|
16
|
+
"separator": "dim",
|
|
17
|
+
"border": "borderMuted"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/theme.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme system for powerline-footer
|
|
3
|
+
*
|
|
4
|
+
* Colors are resolved in order:
|
|
5
|
+
* 1. User overrides from theme.json (if exists)
|
|
6
|
+
* 2. Preset colors
|
|
7
|
+
* 3. Default colors
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Theme, ThemeColor } from "@mariozechner/pi-coding-agent";
|
|
11
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
12
|
+
import { join, dirname } from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import type { ColorScheme, ColorValue, SemanticColor } from "./types.js";
|
|
15
|
+
|
|
16
|
+
// Default color scheme (uses pi theme colors)
|
|
17
|
+
const DEFAULT_COLORS: Required<ColorScheme> = {
|
|
18
|
+
pi: "accent",
|
|
19
|
+
model: "primary",
|
|
20
|
+
path: "muted",
|
|
21
|
+
git: "success",
|
|
22
|
+
gitDirty: "warning",
|
|
23
|
+
gitClean: "success",
|
|
24
|
+
thinking: "muted",
|
|
25
|
+
thinkingHigh: "accent",
|
|
26
|
+
context: "dim",
|
|
27
|
+
contextWarn: "warning",
|
|
28
|
+
contextError: "error",
|
|
29
|
+
cost: "primary",
|
|
30
|
+
tokens: "muted",
|
|
31
|
+
separator: "dim",
|
|
32
|
+
border: "borderMuted",
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Rainbow colors for high thinking levels
|
|
36
|
+
const RAINBOW_COLORS = [
|
|
37
|
+
"#b281d6", "#d787af", "#febc38", "#e4c00f",
|
|
38
|
+
"#89d281", "#00afaf", "#178fb9", "#b281d6",
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
// Cache for user theme overrides
|
|
42
|
+
let userThemeCache: ColorScheme | null = null;
|
|
43
|
+
let userThemeCacheTime = 0;
|
|
44
|
+
const CACHE_TTL = 5000; // 5 seconds
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the path to the theme.json file
|
|
48
|
+
*/
|
|
49
|
+
function getThemePath(): string {
|
|
50
|
+
const extDir = dirname(fileURLToPath(import.meta.url));
|
|
51
|
+
return join(extDir, "theme.json");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Load user theme overrides from theme.json
|
|
56
|
+
*/
|
|
57
|
+
function loadUserTheme(): ColorScheme {
|
|
58
|
+
const now = Date.now();
|
|
59
|
+
if (userThemeCache && now - userThemeCacheTime < CACHE_TTL) {
|
|
60
|
+
return userThemeCache;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const themePath = getThemePath();
|
|
64
|
+
try {
|
|
65
|
+
if (existsSync(themePath)) {
|
|
66
|
+
const content = readFileSync(themePath, "utf-8");
|
|
67
|
+
const parsed = JSON.parse(content);
|
|
68
|
+
userThemeCache = parsed.colors ?? {};
|
|
69
|
+
userThemeCacheTime = now;
|
|
70
|
+
return userThemeCache;
|
|
71
|
+
}
|
|
72
|
+
} catch {
|
|
73
|
+
// Ignore errors, use defaults
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
userThemeCache = {};
|
|
77
|
+
userThemeCacheTime = now;
|
|
78
|
+
return userThemeCache;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Resolve a semantic color to an actual color value
|
|
83
|
+
*/
|
|
84
|
+
export function resolveColor(
|
|
85
|
+
semantic: SemanticColor,
|
|
86
|
+
presetColors?: ColorScheme
|
|
87
|
+
): ColorValue {
|
|
88
|
+
const userTheme = loadUserTheme();
|
|
89
|
+
|
|
90
|
+
// Priority: user overrides > preset colors > defaults
|
|
91
|
+
return userTheme[semantic]
|
|
92
|
+
?? presetColors?.[semantic]
|
|
93
|
+
?? DEFAULT_COLORS[semantic];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Check if a color value is a hex color
|
|
98
|
+
*/
|
|
99
|
+
function isHexColor(color: ColorValue): color is `#${string}` {
|
|
100
|
+
return typeof color === "string" && color.startsWith("#");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Convert hex color to ANSI escape code
|
|
105
|
+
*/
|
|
106
|
+
function hexToAnsi(hex: string): string {
|
|
107
|
+
const h = hex.replace("#", "");
|
|
108
|
+
const r = parseInt(h.slice(0, 2), 16);
|
|
109
|
+
const g = parseInt(h.slice(2, 4), 16);
|
|
110
|
+
const b = parseInt(h.slice(4, 6), 16);
|
|
111
|
+
return `\x1b[38;2;${r};${g};${b}m`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Apply a color to text using the pi theme or custom hex
|
|
116
|
+
*/
|
|
117
|
+
export function applyColor(
|
|
118
|
+
theme: Theme,
|
|
119
|
+
color: ColorValue,
|
|
120
|
+
text: string
|
|
121
|
+
): string {
|
|
122
|
+
if (isHexColor(color)) {
|
|
123
|
+
return `${hexToAnsi(color)}${text}\x1b[0m`;
|
|
124
|
+
}
|
|
125
|
+
return theme.fg(color as ThemeColor, text);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Apply a semantic color to text
|
|
130
|
+
*/
|
|
131
|
+
export function fg(
|
|
132
|
+
theme: Theme,
|
|
133
|
+
semantic: SemanticColor,
|
|
134
|
+
text: string,
|
|
135
|
+
presetColors?: ColorScheme
|
|
136
|
+
): string {
|
|
137
|
+
const color = resolveColor(semantic, presetColors);
|
|
138
|
+
return applyColor(theme, color, text);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Apply rainbow gradient to text (for high thinking levels)
|
|
143
|
+
*/
|
|
144
|
+
export function rainbow(text: string): string {
|
|
145
|
+
let result = "";
|
|
146
|
+
let colorIndex = 0;
|
|
147
|
+
for (const char of text) {
|
|
148
|
+
if (char === " " || char === ":") {
|
|
149
|
+
result += char;
|
|
150
|
+
} else {
|
|
151
|
+
result += hexToAnsi(RAINBOW_COLORS[colorIndex % RAINBOW_COLORS.length]) + char;
|
|
152
|
+
colorIndex++;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result + "\x1b[0m";
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Get the default color scheme
|
|
160
|
+
*/
|
|
161
|
+
export function getDefaultColors(): Required<ColorScheme> {
|
|
162
|
+
return { ...DEFAULT_COLORS };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Clear the user theme cache (for reloading)
|
|
167
|
+
*/
|
|
168
|
+
export function clearThemeCache(): void {
|
|
169
|
+
userThemeCache = null;
|
|
170
|
+
userThemeCacheTime = 0;
|
|
171
|
+
}
|
package/types.ts
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
import type { Theme, ThemeColor } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
// Theme color - either a pi theme color name or a custom hex color
|
|
4
|
+
export type ColorValue = ThemeColor | `#${string}`;
|
|
5
|
+
|
|
6
|
+
// Semantic color names for segments
|
|
7
|
+
export type SemanticColor =
|
|
8
|
+
| "pi"
|
|
9
|
+
| "model"
|
|
10
|
+
| "path"
|
|
11
|
+
| "git"
|
|
12
|
+
| "gitDirty"
|
|
13
|
+
| "gitClean"
|
|
14
|
+
| "thinking"
|
|
15
|
+
| "thinkingHigh"
|
|
16
|
+
| "context"
|
|
17
|
+
| "contextWarn"
|
|
18
|
+
| "contextError"
|
|
19
|
+
| "cost"
|
|
20
|
+
| "tokens"
|
|
21
|
+
| "separator"
|
|
22
|
+
| "border";
|
|
23
|
+
|
|
24
|
+
// Color scheme mapping semantic names to actual colors
|
|
25
|
+
export type ColorScheme = Partial<Record<SemanticColor, ColorValue>>;
|
|
26
|
+
|
|
1
27
|
// Segment identifiers
|
|
2
28
|
export type StatusLineSegmentId =
|
|
3
29
|
| "pi"
|
|
@@ -62,6 +88,8 @@ export interface PresetDef {
|
|
|
62
88
|
secondarySegments?: StatusLineSegmentId[];
|
|
63
89
|
separator: StatusLineSeparatorStyle;
|
|
64
90
|
segmentOptions?: StatusLineSegmentOptions;
|
|
91
|
+
/** Color scheme for this preset */
|
|
92
|
+
colors?: ColorScheme;
|
|
65
93
|
}
|
|
66
94
|
|
|
67
95
|
// Separator definition
|
|
@@ -116,6 +144,10 @@ export interface SegmentContext {
|
|
|
116
144
|
// Options
|
|
117
145
|
options: StatusLineSegmentOptions;
|
|
118
146
|
width: number;
|
|
147
|
+
|
|
148
|
+
// Theming
|
|
149
|
+
theme: Theme;
|
|
150
|
+
colors: ColorScheme;
|
|
119
151
|
}
|
|
120
152
|
|
|
121
153
|
// Rendered segment output
|