pi-catppuccin-footer 0.1.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.
- package/LICENSE +21 -0
- package/README.md +259 -0
- package/assets/catppuccin-footer.png +0 -0
- package/assets/default-pi-footer.png +0 -0
- package/examples/catppuccin-footer.json +30 -0
- package/extensions/catppuccin-footer.ts +533 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David Jensenius
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# pi-catppuccin-footer
|
|
2
|
+
|
|
3
|
+
A configurable [Pi](https://pi.dev) extension that replaces the default footer with a Catppuccin/tmux-style status line.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
<details>
|
|
8
|
+
<summary>Default Pi footer</summary>
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
</details>
|
|
13
|
+
|
|
14
|
+
It is inspired by `tmux-catppuccin` modules and a lualine-style Neovim setup: rounded powerline caps, Catppuccin colors, configurable left/right sections, and live session stats.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- Catppuccin flavors: `mocha`, `macchiato`, `frappe`, `latte`
|
|
19
|
+
- tmux-style connected status modules
|
|
20
|
+
- configurable left/right section order
|
|
21
|
+
- project-local config via `.pi/catppuccin-footer.json`
|
|
22
|
+
- auto-reloads config changes
|
|
23
|
+
- preserves Pi extension statuses
|
|
24
|
+
- shows optional:
|
|
25
|
+
- current directory
|
|
26
|
+
- git branch
|
|
27
|
+
- git dirty counts
|
|
28
|
+
- Pi activity state
|
|
29
|
+
- model name / aliases
|
|
30
|
+
- total tokens
|
|
31
|
+
- last-turn tokens
|
|
32
|
+
- session cost
|
|
33
|
+
- time
|
|
34
|
+
- thinking level
|
|
35
|
+
|
|
36
|
+
## Install from GitHub
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pi install git:github.com/djensenius/pi-catppuccin-footer
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then reload Pi:
|
|
43
|
+
|
|
44
|
+
```txt
|
|
45
|
+
/reload
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Install locally while developing
|
|
49
|
+
|
|
50
|
+
From this repo:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pi install ./path/to/pi-catppuccin-footer
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Or load the extension for one Pi run:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pi -e ./extensions/catppuccin-footer.ts
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quick start
|
|
63
|
+
|
|
64
|
+
After installing, create a global config:
|
|
65
|
+
|
|
66
|
+
```txt
|
|
67
|
+
/catppuccin-footer init --global
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Or create a project-local config that overrides the global config:
|
|
71
|
+
|
|
72
|
+
```txt
|
|
73
|
+
/catppuccin-footer init
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
If a config already exists and you want to replace it:
|
|
77
|
+
|
|
78
|
+
```txt
|
|
79
|
+
/catppuccin-footer init --global --force
|
|
80
|
+
/catppuccin-footer init --force
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Configuration
|
|
84
|
+
|
|
85
|
+
Global config:
|
|
86
|
+
|
|
87
|
+
```txt
|
|
88
|
+
~/.pi/agent/catppuccin-footer.json
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Project-local override:
|
|
92
|
+
|
|
93
|
+
```txt
|
|
94
|
+
.pi/catppuccin-footer.json
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Project config is merged on top of global config. Nested `colors` and `aliases` are merged too.
|
|
98
|
+
|
|
99
|
+
Example:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"flavor": "mocha",
|
|
104
|
+
"enabled": true,
|
|
105
|
+
"style": "tmux",
|
|
106
|
+
"cwdStyle": "short",
|
|
107
|
+
"left": ["mode", "cwd", "git", "gitDiff"],
|
|
108
|
+
"right": ["status", "state", "model", "tokens", "lastTokens", "cost", "time"],
|
|
109
|
+
"timeFormat": "HH:mm",
|
|
110
|
+
"moduleSpacing": 0,
|
|
111
|
+
"autoReload": true,
|
|
112
|
+
"colors": {
|
|
113
|
+
"mode": "mauve",
|
|
114
|
+
"cwd": "blue",
|
|
115
|
+
"git": "green",
|
|
116
|
+
"gitDiff": "green",
|
|
117
|
+
"status": "peach",
|
|
118
|
+
"state": "pink",
|
|
119
|
+
"model": "mauve",
|
|
120
|
+
"tokens": "green",
|
|
121
|
+
"lastTokens": "blue",
|
|
122
|
+
"cost": "yellow",
|
|
123
|
+
"time": "peach",
|
|
124
|
+
"thinking": "pink"
|
|
125
|
+
},
|
|
126
|
+
"aliases": {
|
|
127
|
+
"claude-sonnet-4-5": "sonnet",
|
|
128
|
+
"gemini-2.5-pro": "gemini"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
With `autoReload: true`, config edits are picked up automatically. You can also reload manually:
|
|
134
|
+
|
|
135
|
+
```txt
|
|
136
|
+
/catppuccin-footer reload
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Sections
|
|
140
|
+
|
|
141
|
+
Use these names in `left` and `right` arrays:
|
|
142
|
+
|
|
143
|
+
| Section | Meaning |
|
|
144
|
+
| ------------ | ----------------------------------------- |
|
|
145
|
+
| `mode` | Pi/Yolo mode anchor |
|
|
146
|
+
| `cwd` | Current working directory |
|
|
147
|
+
| `git` | Current git branch |
|
|
148
|
+
| `gitDiff` | Git dirty counts (`+`, `~`, `-`) |
|
|
149
|
+
| `status` | Pi extension status messages |
|
|
150
|
+
| `state` | Pi activity state: idle/thinking/tools |
|
|
151
|
+
| `model` | Active model, with optional aliases |
|
|
152
|
+
| `tokens` | Total session input/output tokens |
|
|
153
|
+
| `lastTokens` | Latest assistant turn input/output tokens |
|
|
154
|
+
| `cost` | Total session cost |
|
|
155
|
+
| `time` | Local time |
|
|
156
|
+
| `thinking` | Current thinking level |
|
|
157
|
+
|
|
158
|
+
## Styles
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
"style": "tmux"
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Available styles:
|
|
165
|
+
|
|
166
|
+
- `tmux` — connected tmux-catppuccin-style modules
|
|
167
|
+
- `twoTone` — connected lualine-style two-tone group
|
|
168
|
+
- `bubble` — standalone rounded bubbles
|
|
169
|
+
|
|
170
|
+
## Colors
|
|
171
|
+
|
|
172
|
+
Available color names:
|
|
173
|
+
|
|
174
|
+
```txt
|
|
175
|
+
mauve
|
|
176
|
+
blue
|
|
177
|
+
green
|
|
178
|
+
yellow
|
|
179
|
+
peach
|
|
180
|
+
pink
|
|
181
|
+
surface
|
|
182
|
+
muted
|
|
183
|
+
text
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Commands
|
|
187
|
+
|
|
188
|
+
```txt
|
|
189
|
+
/catppuccin-footer # toggle on/off
|
|
190
|
+
/catppuccin-footer on # enable
|
|
191
|
+
/catppuccin-footer off # disable
|
|
192
|
+
/catppuccin-footer reload # reload config
|
|
193
|
+
/catppuccin-footer init --global # write default global config
|
|
194
|
+
/catppuccin-footer init --global --force # overwrite default global config
|
|
195
|
+
/catppuccin-footer init # write default project config
|
|
196
|
+
/catppuccin-footer init --force # overwrite default project config
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Development
|
|
200
|
+
|
|
201
|
+
This repo includes local tooling for formatting, linting, typechecking, tests, and package verification.
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
npm install
|
|
205
|
+
npm run check
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Or with `just`:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
just ci
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Or with `mise`:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
mise run check
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
The test suite uses Vitest.
|
|
221
|
+
|
|
222
|
+
## Publishing
|
|
223
|
+
|
|
224
|
+
To publish to GitHub:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
git init
|
|
228
|
+
git add .
|
|
229
|
+
git commit -m "Initial pi-catppuccin-footer package"
|
|
230
|
+
git branch -M main
|
|
231
|
+
git remote add origin git@github.com:djensenius/pi-catppuccin-footer.git
|
|
232
|
+
git push -u origin main
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Users can then install with:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
pi install git:github.com/djensenius/pi-catppuccin-footer
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
To publish to npm:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
npm publish
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Users can then install with:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
pi install npm:pi-catppuccin-footer
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Security
|
|
254
|
+
|
|
255
|
+
Pi extensions run with full system permissions. Review extensions before installing them.
|
|
256
|
+
|
|
257
|
+
## License
|
|
258
|
+
|
|
259
|
+
MIT
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"flavor": "mocha",
|
|
3
|
+
"enabled": true,
|
|
4
|
+
"style": "tmux",
|
|
5
|
+
"cwdStyle": "short",
|
|
6
|
+
"left": ["mode", "cwd", "git", "gitDiff"],
|
|
7
|
+
"right": ["status", "state", "model", "tokens", "lastTokens", "cost", "time"],
|
|
8
|
+
"timeFormat": "HH:mm",
|
|
9
|
+
"moduleSpacing": 0,
|
|
10
|
+
"autoReload": true,
|
|
11
|
+
"colors": {
|
|
12
|
+
"mode": "mauve",
|
|
13
|
+
"cwd": "blue",
|
|
14
|
+
"git": "green",
|
|
15
|
+
"gitDiff": "green",
|
|
16
|
+
"status": "peach",
|
|
17
|
+
"state": "pink",
|
|
18
|
+
"model": "mauve",
|
|
19
|
+
"tokens": "green",
|
|
20
|
+
"lastTokens": "blue",
|
|
21
|
+
"cost": "yellow",
|
|
22
|
+
"time": "peach",
|
|
23
|
+
"thinking": "pink"
|
|
24
|
+
},
|
|
25
|
+
"aliases": {
|
|
26
|
+
"claude-sonnet-4-5": "sonnet",
|
|
27
|
+
"gemini-2.5-pro": "gemini",
|
|
28
|
+
"gpt-5.5": "gpt-5.5"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, watch, writeFileSync, type FSWatcher } from "node:fs";
|
|
5
|
+
import { basename, relative } from "node:path";
|
|
6
|
+
|
|
7
|
+
const CONFIG_PATH = ".pi/catppuccin-footer.json";
|
|
8
|
+
const GLOBAL_CONFIG_PATH = `${process.env.PI_CODING_AGENT_DIR ?? `${process.env.HOME}/.pi/agent`}/catppuccin-footer.json`;
|
|
9
|
+
|
|
10
|
+
type Flavor = "latte" | "frappe" | "macchiato" | "mocha";
|
|
11
|
+
type ColorName = "mauve" | "blue" | "green" | "yellow" | "peach" | "pink" | "surface" | "muted" | "text";
|
|
12
|
+
type SectionName =
|
|
13
|
+
| "mode"
|
|
14
|
+
| "cwd"
|
|
15
|
+
| "git"
|
|
16
|
+
| "gitDiff"
|
|
17
|
+
| "status"
|
|
18
|
+
| "state"
|
|
19
|
+
| "model"
|
|
20
|
+
| "tokens"
|
|
21
|
+
| "lastTokens"
|
|
22
|
+
| "cost"
|
|
23
|
+
| "time"
|
|
24
|
+
| "thinking";
|
|
25
|
+
type CwdStyle = "short" | "basename" | "full";
|
|
26
|
+
type SegmentStyle = "twoTone" | "bubble" | "tmux";
|
|
27
|
+
type ActivityState = "idle" | "thinking" | "tools";
|
|
28
|
+
|
|
29
|
+
interface FooterConfig {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
flavor: Flavor;
|
|
32
|
+
style: SegmentStyle;
|
|
33
|
+
cwdStyle: CwdStyle;
|
|
34
|
+
left: SectionName[];
|
|
35
|
+
right: SectionName[];
|
|
36
|
+
timeFormat: "HH:mm" | "HH:mm:ss";
|
|
37
|
+
moduleSpacing: number;
|
|
38
|
+
autoReload: boolean;
|
|
39
|
+
colors: Partial<Record<SectionName, ColorName>>;
|
|
40
|
+
aliases: Record<string, string>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const DEFAULT_CONFIG: FooterConfig = {
|
|
44
|
+
enabled: true,
|
|
45
|
+
flavor: "mocha",
|
|
46
|
+
style: "tmux",
|
|
47
|
+
cwdStyle: "short",
|
|
48
|
+
left: ["mode", "cwd", "git", "gitDiff"],
|
|
49
|
+
right: ["status", "state", "model", "tokens", "lastTokens", "cost", "time"],
|
|
50
|
+
timeFormat: "HH:mm",
|
|
51
|
+
moduleSpacing: 0,
|
|
52
|
+
autoReload: true,
|
|
53
|
+
colors: {
|
|
54
|
+
mode: "mauve",
|
|
55
|
+
cwd: "blue",
|
|
56
|
+
git: "green",
|
|
57
|
+
gitDiff: "green",
|
|
58
|
+
status: "peach",
|
|
59
|
+
state: "pink",
|
|
60
|
+
model: "mauve",
|
|
61
|
+
tokens: "green",
|
|
62
|
+
lastTokens: "blue",
|
|
63
|
+
cost: "yellow",
|
|
64
|
+
time: "peach",
|
|
65
|
+
thinking: "pink",
|
|
66
|
+
},
|
|
67
|
+
aliases: {},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const PALETTES = {
|
|
71
|
+
latte: {
|
|
72
|
+
base: "#eff1f5",
|
|
73
|
+
text: "#4c4f69",
|
|
74
|
+
surface: "#ccd0da",
|
|
75
|
+
muted: "#6c6f85",
|
|
76
|
+
mauve: "#8839ef",
|
|
77
|
+
blue: "#1e66f5",
|
|
78
|
+
green: "#40a02b",
|
|
79
|
+
yellow: "#df8e1d",
|
|
80
|
+
peach: "#fe640b",
|
|
81
|
+
pink: "#ea76cb",
|
|
82
|
+
},
|
|
83
|
+
frappe: {
|
|
84
|
+
base: "#303446",
|
|
85
|
+
text: "#c6d0f5",
|
|
86
|
+
surface: "#414559",
|
|
87
|
+
muted: "#a5adce",
|
|
88
|
+
mauve: "#ca9ee6",
|
|
89
|
+
blue: "#8caaee",
|
|
90
|
+
green: "#a6d189",
|
|
91
|
+
yellow: "#e5c890",
|
|
92
|
+
peach: "#ef9f76",
|
|
93
|
+
pink: "#f4b8e4",
|
|
94
|
+
},
|
|
95
|
+
macchiato: {
|
|
96
|
+
base: "#24273a",
|
|
97
|
+
text: "#cad3f5",
|
|
98
|
+
surface: "#363a4f",
|
|
99
|
+
muted: "#a5adcb",
|
|
100
|
+
mauve: "#c6a0f6",
|
|
101
|
+
blue: "#8aadf4",
|
|
102
|
+
green: "#a6da95",
|
|
103
|
+
yellow: "#eed49f",
|
|
104
|
+
peach: "#f5a97f",
|
|
105
|
+
pink: "#f5bde6",
|
|
106
|
+
},
|
|
107
|
+
mocha: {
|
|
108
|
+
base: "#1e1e2e",
|
|
109
|
+
text: "#cdd6f4",
|
|
110
|
+
surface: "#313244",
|
|
111
|
+
muted: "#a6adc8",
|
|
112
|
+
mauve: "#cba6f7",
|
|
113
|
+
blue: "#89b4fa",
|
|
114
|
+
green: "#a6e3a1",
|
|
115
|
+
yellow: "#f9e2af",
|
|
116
|
+
peach: "#fab387",
|
|
117
|
+
pink: "#f5c2e7",
|
|
118
|
+
},
|
|
119
|
+
} as const;
|
|
120
|
+
|
|
121
|
+
function hexToRgb(hex: string): [number, number, number] {
|
|
122
|
+
const normalized = hex.replace("#", "");
|
|
123
|
+
return [
|
|
124
|
+
Number.parseInt(normalized.slice(0, 2), 16),
|
|
125
|
+
Number.parseInt(normalized.slice(2, 4), 16),
|
|
126
|
+
Number.parseInt(normalized.slice(4, 6), 16),
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function fg(hex: string, text: string): string {
|
|
131
|
+
const [r, g, b] = hexToRgb(hex);
|
|
132
|
+
return `\x1b[38;2;${r};${g};${b}m${text}\x1b[39m`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function bg(hex: string, text: string): string {
|
|
136
|
+
const [r, g, b] = hexToRgb(hex);
|
|
137
|
+
return `\x1b[48;2;${r};${g};${b}m${text}\x1b[49m`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function styled(text: string, foreground: string, background: string): string {
|
|
141
|
+
const [fr, fgValue, fb] = hexToRgb(foreground);
|
|
142
|
+
const [br, bgValue, bb] = hexToRgb(background);
|
|
143
|
+
return `\x1b[38;2;${fr};${fgValue};${fb}m\x1b[48;2;${br};${bgValue};${bb}m${text}\x1b[39m\x1b[49m`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function readJsonConfig(path: string): Partial<FooterConfig> {
|
|
147
|
+
if (!existsSync(path)) return {};
|
|
148
|
+
try {
|
|
149
|
+
return JSON.parse(readFileSync(path, "utf8")) as Partial<FooterConfig>;
|
|
150
|
+
} catch {
|
|
151
|
+
return {};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function readConfig(cwd: string): FooterConfig {
|
|
156
|
+
const globalRaw = readJsonConfig(GLOBAL_CONFIG_PATH);
|
|
157
|
+
const projectRaw = readJsonConfig(`${cwd}/${CONFIG_PATH}`);
|
|
158
|
+
const merged = { ...globalRaw, ...projectRaw };
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
...DEFAULT_CONFIG,
|
|
162
|
+
...merged,
|
|
163
|
+
left: Array.isArray(merged.left) ? merged.left : DEFAULT_CONFIG.left,
|
|
164
|
+
right: Array.isArray(merged.right) ? merged.right : DEFAULT_CONFIG.right,
|
|
165
|
+
colors: { ...DEFAULT_CONFIG.colors, ...(globalRaw.colors ?? {}), ...(projectRaw.colors ?? {}) },
|
|
166
|
+
aliases: { ...DEFAULT_CONFIG.aliases, ...(globalRaw.aliases ?? {}), ...(projectRaw.aliases ?? {}) },
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function formatCwd(cwd: string, style: CwdStyle): string {
|
|
171
|
+
if (style === "full") return cwd;
|
|
172
|
+
if (style === "basename") return basename(cwd) || cwd;
|
|
173
|
+
|
|
174
|
+
const home = process.env.HOME;
|
|
175
|
+
if (home && cwd === home) return "~";
|
|
176
|
+
if (home && cwd.startsWith(`${home}/`)) return `~/${relative(home, cwd)}`;
|
|
177
|
+
return cwd;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function formatTime(format: FooterConfig["timeFormat"]): string {
|
|
181
|
+
const now = new Date();
|
|
182
|
+
const hh = String(now.getHours()).padStart(2, "0");
|
|
183
|
+
const mm = String(now.getMinutes()).padStart(2, "0");
|
|
184
|
+
const ss = String(now.getSeconds()).padStart(2, "0");
|
|
185
|
+
return format === "HH:mm:ss" ? `${hh}:${mm}:${ss}` : `${hh}:${mm}`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function assistantStats(ctx: any): {
|
|
189
|
+
input: number;
|
|
190
|
+
output: number;
|
|
191
|
+
cost: number;
|
|
192
|
+
lastInput: number;
|
|
193
|
+
lastOutput: number;
|
|
194
|
+
} {
|
|
195
|
+
let input = 0;
|
|
196
|
+
let output = 0;
|
|
197
|
+
let cost = 0;
|
|
198
|
+
let lastInput = 0;
|
|
199
|
+
let lastOutput = 0;
|
|
200
|
+
|
|
201
|
+
for (const entry of ctx.sessionManager.getBranch()) {
|
|
202
|
+
if (entry.type !== "message" || entry.message.role !== "assistant") continue;
|
|
203
|
+
const message = entry.message as AssistantMessage;
|
|
204
|
+
const usage = message.usage;
|
|
205
|
+
if (!usage) continue;
|
|
206
|
+
input += usage.input ?? 0;
|
|
207
|
+
output += usage.output ?? 0;
|
|
208
|
+
cost += usage.cost?.total ?? 0;
|
|
209
|
+
lastInput = usage.input ?? 0;
|
|
210
|
+
lastOutput = usage.output ?? 0;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return { input, output, cost, lastInput, lastOutput };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function compactNumber(n: number): string {
|
|
217
|
+
if (n < 1000) return `${n}`;
|
|
218
|
+
if (n < 1_000_000) return `${(n / 1000).toFixed(1)}k`;
|
|
219
|
+
return `${(n / 1_000_000).toFixed(1)}m`;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function splitIcon(value: string): { icon: string; label: string } {
|
|
223
|
+
const [icon, ...rest] = value.split(" ");
|
|
224
|
+
return rest.length > 0 ? { icon, label: rest.join(" ") } : { icon: "", label: value };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function parseGitDiff(porcelain: string): string | undefined {
|
|
228
|
+
if (!porcelain.trim()) return " ✓";
|
|
229
|
+
|
|
230
|
+
let added = 0;
|
|
231
|
+
let modified = 0;
|
|
232
|
+
let deleted = 0;
|
|
233
|
+
|
|
234
|
+
for (const line of porcelain.split("\n")) {
|
|
235
|
+
if (!line) continue;
|
|
236
|
+
const x = line[0] ?? " ";
|
|
237
|
+
const y = line[1] ?? " ";
|
|
238
|
+
if (x === "?" && y === "?") added++;
|
|
239
|
+
else {
|
|
240
|
+
if (x === "A" || y === "A") added++;
|
|
241
|
+
if (x === "M" || y === "M" || x === "R" || y === "R") modified++;
|
|
242
|
+
if (x === "D" || y === "D") deleted++;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const parts = [];
|
|
247
|
+
if (added) parts.push(`+${added}`);
|
|
248
|
+
if (modified) parts.push(`~${modified}`);
|
|
249
|
+
if (deleted) parts.push(`-${deleted}`);
|
|
250
|
+
return parts.length ? ` ${parts.join(" ")}` : " ✓";
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function sectionValue(
|
|
254
|
+
name: SectionName,
|
|
255
|
+
ctx: any,
|
|
256
|
+
footerData: any,
|
|
257
|
+
config: FooterConfig,
|
|
258
|
+
activityState: ActivityState,
|
|
259
|
+
gitDiff: string | undefined,
|
|
260
|
+
): string | undefined {
|
|
261
|
+
const stats = assistantStats(ctx);
|
|
262
|
+
|
|
263
|
+
switch (name) {
|
|
264
|
+
case "mode":
|
|
265
|
+
return "π yolo";
|
|
266
|
+
case "cwd":
|
|
267
|
+
return ` ${formatCwd(ctx.cwd, config.cwdStyle)}`;
|
|
268
|
+
case "git": {
|
|
269
|
+
const branch = footerData.getGitBranch?.();
|
|
270
|
+
return branch ? ` ${branch}` : undefined;
|
|
271
|
+
}
|
|
272
|
+
case "gitDiff":
|
|
273
|
+
return gitDiff;
|
|
274
|
+
case "status": {
|
|
275
|
+
const statuses = footerData.getExtensionStatuses?.();
|
|
276
|
+
if (!statuses || statuses.size === 0) return undefined;
|
|
277
|
+
return [...statuses.values()].filter(Boolean).join(" ");
|
|
278
|
+
}
|
|
279
|
+
case "state":
|
|
280
|
+
return activityState === "tools" ? " tools" : activityState === "thinking" ? " thinking" : " idle";
|
|
281
|
+
case "model": {
|
|
282
|
+
const model = ctx.model?.id;
|
|
283
|
+
return model ? ` ${config.aliases[model] ?? model}` : " no model";
|
|
284
|
+
}
|
|
285
|
+
case "tokens":
|
|
286
|
+
return ` ↑${compactNumber(stats.input)} ↓${compactNumber(stats.output)}`;
|
|
287
|
+
case "lastTokens":
|
|
288
|
+
return stats.lastInput || stats.lastOutput
|
|
289
|
+
? ` +${compactNumber(stats.lastInput)}/${compactNumber(stats.lastOutput)}`
|
|
290
|
+
: undefined;
|
|
291
|
+
case "cost":
|
|
292
|
+
return ` $${stats.cost.toFixed(3)}`;
|
|
293
|
+
case "time":
|
|
294
|
+
return ` ${formatTime(config.timeFormat)}`;
|
|
295
|
+
case "thinking": {
|
|
296
|
+
const level = typeof piApi?.getThinkingLevel === "function" ? piApi.getThinkingLevel() : undefined;
|
|
297
|
+
return level ? ` ${level}` : undefined;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
let piApi: ExtensionAPI | undefined;
|
|
303
|
+
|
|
304
|
+
function sectionColor(
|
|
305
|
+
name: SectionName,
|
|
306
|
+
index: number,
|
|
307
|
+
config: FooterConfig,
|
|
308
|
+
palette: (typeof PALETTES)[Flavor],
|
|
309
|
+
): string {
|
|
310
|
+
const fallback: ColorName[] = ["mauve", "blue", "green", "yellow", "peach", "pink"];
|
|
311
|
+
const colorName = config.colors[name] ?? fallback[index % fallback.length];
|
|
312
|
+
return palette[colorName] ?? palette.mauve;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function renderSegments(
|
|
316
|
+
names: SectionName[],
|
|
317
|
+
ctx: any,
|
|
318
|
+
footerData: any,
|
|
319
|
+
config: FooterConfig,
|
|
320
|
+
activityState: ActivityState,
|
|
321
|
+
gitDiff: string | undefined,
|
|
322
|
+
reverse = false,
|
|
323
|
+
): string {
|
|
324
|
+
const palette = PALETTES[config.flavor] ?? PALETTES.mocha;
|
|
325
|
+
const entries = names
|
|
326
|
+
.map((name) => ({ name, value: sectionValue(name, ctx, footerData, config, activityState, gitDiff) }))
|
|
327
|
+
.filter((entry): entry is { name: SectionName; value: string } => Boolean(entry.value));
|
|
328
|
+
|
|
329
|
+
const ordered = reverse ? [...entries].reverse() : entries;
|
|
330
|
+
|
|
331
|
+
if (config.style === "bubble" || config.style === "tmux") {
|
|
332
|
+
return ordered
|
|
333
|
+
.map(({ name, value }, index) => {
|
|
334
|
+
const accent = sectionColor(name, index, config, palette);
|
|
335
|
+
const textColor = config.flavor === "latte" ? palette.base : palette.base;
|
|
336
|
+
const { icon, label } = splitIcon(value);
|
|
337
|
+
|
|
338
|
+
if (config.style === "bubble") {
|
|
339
|
+
return `${styled("", accent, palette.base)}${styled(` ${value} `, textColor, accent)}${styled("", accent, palette.base)}`;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const iconPart = icon ? styled(` ${icon} `, textColor, accent) : "";
|
|
343
|
+
const labelPart = styled(` ${label} `, palette.text, palette.surface);
|
|
344
|
+
const capBg = index === 0 ? palette.base : palette.surface;
|
|
345
|
+
const leftCap = styled("", accent, capBg);
|
|
346
|
+
const rightCap = index === ordered.length - 1 ? styled("", palette.surface, palette.base) : "";
|
|
347
|
+
return `${leftCap}${iconPart}${labelPart}${rightCap}`;
|
|
348
|
+
})
|
|
349
|
+
.join(" ".repeat(Math.max(0, config.moduleSpacing)));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return ordered
|
|
353
|
+
.map(({ name, value }, index) => {
|
|
354
|
+
const accent = sectionColor(name, index, config, palette);
|
|
355
|
+
const textColor = config.flavor === "latte" ? palette.base : palette.base;
|
|
356
|
+
const isFirst = index === 0;
|
|
357
|
+
const isLast = index === ordered.length - 1;
|
|
358
|
+
const leftCap = isFirst ? fg(accent, "") : "";
|
|
359
|
+
const { icon, label } = splitIcon(value);
|
|
360
|
+
const iconPart = icon ? styled(` ${icon} `, textColor, accent) : "";
|
|
361
|
+
const labelPart = styled(` ${label} `, palette.text, palette.surface);
|
|
362
|
+
const rightCap = isLast ? fg(palette.surface, "") : "";
|
|
363
|
+
return `${leftCap}${iconPart}${labelPart}${rightCap}`;
|
|
364
|
+
})
|
|
365
|
+
.join("");
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export default function (pi: ExtensionAPI) {
|
|
369
|
+
piApi = pi;
|
|
370
|
+
let config = DEFAULT_CONFIG;
|
|
371
|
+
let enabled = true;
|
|
372
|
+
let activityState: ActivityState = "idle";
|
|
373
|
+
let gitDiff: string | undefined;
|
|
374
|
+
let requestRender: (() => void) | undefined;
|
|
375
|
+
let projectWatcher: FSWatcher | undefined;
|
|
376
|
+
let globalWatcher: FSWatcher | undefined;
|
|
377
|
+
|
|
378
|
+
async function refreshGitDiff(_ctx: any) {
|
|
379
|
+
try {
|
|
380
|
+
const result = await pi.exec("git", ["status", "--porcelain"], { timeout: 2000 });
|
|
381
|
+
gitDiff = result.code === 0 ? parseGitDiff(result.stdout ?? "") : undefined;
|
|
382
|
+
} catch {
|
|
383
|
+
gitDiff = undefined;
|
|
384
|
+
}
|
|
385
|
+
requestRender?.();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function reloadConfig(ctx: any) {
|
|
389
|
+
config = readConfig(ctx.cwd);
|
|
390
|
+
enabled = config.enabled;
|
|
391
|
+
installFooter(ctx);
|
|
392
|
+
void refreshGitDiff(ctx);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function installConfigWatcher(ctx: any) {
|
|
396
|
+
projectWatcher?.close();
|
|
397
|
+
globalWatcher?.close();
|
|
398
|
+
projectWatcher = undefined;
|
|
399
|
+
globalWatcher = undefined;
|
|
400
|
+
if (!config.autoReload) return;
|
|
401
|
+
|
|
402
|
+
const projectPath = `${ctx.cwd}/${CONFIG_PATH}`;
|
|
403
|
+
if (existsSync(projectPath)) {
|
|
404
|
+
projectWatcher = watch(projectPath, { persistent: false }, () => {
|
|
405
|
+
reloadConfig(ctx);
|
|
406
|
+
requestRender?.();
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (existsSync(GLOBAL_CONFIG_PATH)) {
|
|
411
|
+
globalWatcher = watch(GLOBAL_CONFIG_PATH, { persistent: false }, () => {
|
|
412
|
+
reloadConfig(ctx);
|
|
413
|
+
requestRender?.();
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function installFooter(ctx: any) {
|
|
419
|
+
if (!enabled) {
|
|
420
|
+
ctx.ui.setFooter(undefined);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
ctx.ui.setFooter((tui: any, _theme: any, footerData: any) => {
|
|
425
|
+
requestRender = () => tui.requestRender();
|
|
426
|
+
const unsubscribe =
|
|
427
|
+
footerData.onBranchChange?.(() => {
|
|
428
|
+
void refreshGitDiff(ctx);
|
|
429
|
+
tui.requestRender();
|
|
430
|
+
}) ?? (() => {});
|
|
431
|
+
const timer = setInterval(() => {
|
|
432
|
+
void refreshGitDiff(ctx);
|
|
433
|
+
tui.requestRender();
|
|
434
|
+
}, 30_000);
|
|
435
|
+
|
|
436
|
+
return {
|
|
437
|
+
dispose() {
|
|
438
|
+
unsubscribe();
|
|
439
|
+
clearInterval(timer);
|
|
440
|
+
if (requestRender) requestRender = undefined;
|
|
441
|
+
},
|
|
442
|
+
invalidate() {},
|
|
443
|
+
render(width: number): string[] {
|
|
444
|
+
if (!config.enabled) return [""];
|
|
445
|
+
|
|
446
|
+
const palette = PALETTES[config.flavor] ?? PALETTES.mocha;
|
|
447
|
+
const left = renderSegments(config.left, ctx, footerData, config, activityState, gitDiff);
|
|
448
|
+
const right = renderSegments(config.right, ctx, footerData, config, activityState, gitDiff, true);
|
|
449
|
+
const gap = Math.max(1, width - visibleWidth(left) - visibleWidth(right));
|
|
450
|
+
const line = bg(palette.base, left + " ".repeat(gap) + right);
|
|
451
|
+
return [truncateToWidth(line, width, "")];
|
|
452
|
+
},
|
|
453
|
+
};
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
installConfigWatcher(ctx);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
460
|
+
reloadConfig(ctx);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
pi.on("turn_start", async (_event, ctx) => {
|
|
464
|
+
activityState = "thinking";
|
|
465
|
+
requestRender?.();
|
|
466
|
+
void refreshGitDiff(ctx);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
pi.on("tool_execution_start", async (_event, _ctx) => {
|
|
470
|
+
activityState = "tools";
|
|
471
|
+
requestRender?.();
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
pi.on("agent_end", async (_event, ctx) => {
|
|
475
|
+
activityState = "idle";
|
|
476
|
+
requestRender?.();
|
|
477
|
+
void refreshGitDiff(ctx);
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
pi.on("session_shutdown", async () => {
|
|
481
|
+
projectWatcher?.close();
|
|
482
|
+
globalWatcher?.close();
|
|
483
|
+
projectWatcher = undefined;
|
|
484
|
+
globalWatcher = undefined;
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
const catppuccinFooterHandler = async (args: string, ctx: any) => {
|
|
488
|
+
const command = args.trim();
|
|
489
|
+
|
|
490
|
+
if (
|
|
491
|
+
command === "init" ||
|
|
492
|
+
command === "init --force" ||
|
|
493
|
+
command === "init --global" ||
|
|
494
|
+
command === "init --global --force"
|
|
495
|
+
) {
|
|
496
|
+
const global = command.includes("--global");
|
|
497
|
+
const path = global ? GLOBAL_CONFIG_PATH : `${ctx.cwd}/${CONFIG_PATH}`;
|
|
498
|
+
const displayPath = global ? GLOBAL_CONFIG_PATH : CONFIG_PATH;
|
|
499
|
+
const force = command.endsWith("--force");
|
|
500
|
+
|
|
501
|
+
if (existsSync(path) && !force) {
|
|
502
|
+
const overwrite = await ctx.ui.confirm(
|
|
503
|
+
"Overwrite Catppuccin footer config?",
|
|
504
|
+
`${displayPath} already exists. Replace it with the default config?`,
|
|
505
|
+
);
|
|
506
|
+
if (!overwrite) return;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
mkdirSync(global ? GLOBAL_CONFIG_PATH.slice(0, GLOBAL_CONFIG_PATH.lastIndexOf("/")) : `${ctx.cwd}/.pi`, {
|
|
510
|
+
recursive: true,
|
|
511
|
+
});
|
|
512
|
+
writeFileSync(path, `${JSON.stringify(DEFAULT_CONFIG, null, 2)}\n`, "utf8");
|
|
513
|
+
reloadConfig(ctx);
|
|
514
|
+
ctx.ui.notify(`Wrote ${displayPath}`, "info");
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (command === "reload") {
|
|
519
|
+
reloadConfig(ctx);
|
|
520
|
+
ctx.ui.notify("Catppuccin footer config reloaded", "info");
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
enabled = command === "on" ? true : command === "off" ? false : !enabled;
|
|
525
|
+
installFooter(ctx);
|
|
526
|
+
ctx.ui.notify(`Catppuccin footer ${enabled ? "enabled" : "disabled"}`, "info");
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
pi.registerCommand("catppuccin-footer", {
|
|
530
|
+
description: "Toggle, initialize, or reload the Catppuccin-style configurable footer",
|
|
531
|
+
handler: catppuccinFooterHandler,
|
|
532
|
+
});
|
|
533
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-catppuccin-footer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A Catppuccin/tmux-style configurable footer extension for Pi.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi-extension",
|
|
8
|
+
"catppuccin",
|
|
9
|
+
"tmux",
|
|
10
|
+
"footer",
|
|
11
|
+
"statusline"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"files": [
|
|
16
|
+
"assets",
|
|
17
|
+
"extensions",
|
|
18
|
+
"examples",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"pi": {
|
|
23
|
+
"extensions": [
|
|
24
|
+
"./extensions/catppuccin-footer.ts"
|
|
25
|
+
],
|
|
26
|
+
"image": "https://raw.githubusercontent.com/djensenius/pi-catppuccin-footer/main/assets/catppuccin-footer.png"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@earendil-works/pi-ai": "*",
|
|
30
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
31
|
+
"@earendil-works/pi-tui": "*"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@earendil-works/pi-ai": "^0.74.0",
|
|
35
|
+
"@earendil-works/pi-coding-agent": "^0.74.0",
|
|
36
|
+
"@earendil-works/pi-tui": "^0.74.0",
|
|
37
|
+
"@eslint/js": "^10.0.1",
|
|
38
|
+
"@types/node": "^25.6.2",
|
|
39
|
+
"eslint": "^10.3.0",
|
|
40
|
+
"prettier": "^3.8.3",
|
|
41
|
+
"typescript": "^6.0.3",
|
|
42
|
+
"typescript-eslint": "^8.59.2",
|
|
43
|
+
"vite": "^8.0.12",
|
|
44
|
+
"vitest": "^4.1.5"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"format": "prettier --write .",
|
|
48
|
+
"format:check": "prettier --check .",
|
|
49
|
+
"lint": "eslint .",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"check": "npm run format:check && npm run lint && npm run typecheck && npm test && npm run pack:check",
|
|
53
|
+
"ci": "npm run check",
|
|
54
|
+
"pack:check": "npm pack --dry-run"
|
|
55
|
+
}
|
|
56
|
+
}
|