repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

fix(pi/footer): import Key from pi-tui, not pi-coding-agent

1cfa6a132183b8b610f2f3bfd1bffcf92b116876

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (2)

+313 / −1 text lines

pi/agent/extensions/footer/index.ts

Modified

+1 / −1 text lines

14 14 import type { ExtensionAPI, ExtensionContext, Theme, ThemeColor } from "@mariozechner/pi-coding-agent";
15 -import { Key } from "@mariozechner/pi-coding-agent";
15 +import { Key } from "@mariozechner/pi-tui";
16 16 import { truncateToWidth, visibleWidth } from "@mariozechner/pi-tui";
17 17 import { renderContinuousBar, renderBlocksBar, type BarStyle } from "./progress";

pi/agent/previews/neko-preview.ts

Added
new file mode 100644

+312 / −0 text lines

1 +#!/usr/bin/env bun
2 +/**
3 + * Standalone neko sprite preview.
4 + *
5 + * Run in a real terminal:
6 + * bun agent/extensions/neko-preview.ts
7 + *
8 + * Faster/slower:
9 + * NEKO_PREVIEW_FPS=12 bun agent/extensions/neko-preview.ts
10 + *
11 + * Captured/non-TTY output prints one finite animation cycle.
12 + */
14 +type Facing = "left" | "right";
15 +type Motion = "idle" | "walking";
16 +type Activity = "normal" | "thinking" | "working" | "compacting" | "error" | "sleeping";
18 +type SpriteSet = Record<Motion, Record<Facing, string[]>>;
20 +// ANSI palette only. No RGB/truecolor.
21 +const A = {
22 + reset: "\x1b[0m",
23 + dim: "\x1b[2m",
24 + bold: "\x1b[1m",
25 + gray: "\x1b[90m",
26 + red: "\x1b[31m",
27 + yellow: "\x1b[33m",
28 + blue: "\x1b[34m",
29 + magenta: "\x1b[35m",
30 + cyan: "\x1b[36m",
31 +} as const;
33 +const ACTIVITY_COLOR: Record<Activity, string> = {
34 + normal: A.cyan,
35 + thinking: A.blue,
36 + working: A.yellow,
37 + compacting: A.magenta,
38 + error: A.red,
39 + sleeping: A.gray,
40 +};
42 +const ACTIVITY_ORDER: Activity[] = ["normal", "thinking", "working", "compacting", "error", "sleeping"];
44 +// Nerd Font icons:  fa-cog,  oct-test-tube-ish, 󰒲 md-archive/box-ish may vary by font.
45 +// Keep each icon position stable inside a state to avoid sprite jump.
46 +const SPRITES: Record<Activity, SpriteSet> = {
47 + normal: {
48 + idle: {
49 + left: [
50 + "(=^・ω・^=) ",
51 + "(=^・ω・^=) ",
52 + "(=^˘ω˘^=) ",
53 + "(=^・ω・^=)~ ",
54 + "(=^・ω・^=)~~ ",
55 + "(=^・ω・^=)~ ",
56 + ],
57 + right: [
58 + " (=^・ω・^=)",
59 + " (=^・ω・^=)",
60 + " (=^˘ω˘^=)",
61 + " ~(=^・ω・^=)",
62 + " ~~(=^・ω・^=)",
63 + " ~(=^・ω・^=)",
64 + ],
65 + },
66 + walking: {
67 + left: [
68 + "(~^・ω・^∿)~~ ",
69 + "(~^・ω・^∿)~ ",
70 + "(~^・ω・^∿)< ",
71 + "(~^・ω・^∿)~ ",
72 + ],
73 + right: [
74 + " ~~(∿^・ω・^~)",
75 + " ~(∿^・ω・^~)",
76 + " >(∿^・ω・^~)",
77 + " ~(∿^・ω・^~)",
78 + ],
79 + },
80 + },
82 + thinking: {
83 + idle: {
84 + left: [
85 + "(?^・ω・^?) ",
86 + "(?^・ω・^?) . ",
87 + "(?^・ω・^?) ..",
88 + "(?^˘ω˘^?) ..",
89 + "(?^・ω・^?) ..",
90 + "(?^・ω・^?) . ",
91 + ],
92 + right: [
93 + " (?^・ω・^?)",
94 + " . (?^・ω・^?)",
95 + ".. (?^・ω・^?)",
96 + ".. (?^˘ω˘^?)",
97 + ".. (?^・ω・^?)",
98 + " . (?^・ω・^?)",
99 + ],
100 + },
101 + walking: {
102 + left: [
103 + "(?^・ω・^∿)?? ",
104 + "(?^・ω・^∿)? ",
105 + "(?^・ω・^∿)< ",
106 + "(?^˘ω˘^∿)? ",
107 + ],
108 + right: [
109 + " ??(∿^・ω・^?)",
110 + " ?(∿^・ω・^?)",
111 + " >(∿^・ω・^?)",
112 + " ?(∿^˘ω˘^?)",
113 + ],
114 + },
115 + },
117 + working: {
118 + idle: {
119 + left: [
120 + "(=^・ω・^=)  ",
121 + "(=^>ω<^=)  ",
122 + "(=^・ω・^=)  ",
123 + "(=^>ω<^=)  ",
124 + ],
125 + right: [
126 + "  (=^・ω・^=)",
127 + "  (=^>ω<^=)",
128 + "  (=^・ω・^=)",
129 + "  (=^>ω<^=)",
130 + ],
131 + },
132 + walking: {
133 + left: [
134 + "(^・ω・^∿)~~ ",
135 + "(^・ω・^∿)~ ",
136 + "(^>ω<^∿)< ",
137 + "(^・ω・^∿)~ ",
138 + ],
139 + right: [
140 + " ~~(∿^・ω・^)",
141 + " ~(∿^・ω・^)",
142 + " >(∿^>ω<^)",
143 + " ~(∿^・ω・^)",
144 + ],
145 + },
146 + },
148 + compacting: {
149 + idle: {
150 + left: [
151 + "[=^・ω・^=] ",
152 + "[=^˘ω˘^=] ",
153 + "[=^・ω・^=]▣ ",
154 + "[=^・ω・^=]▥ ",
155 + ],
156 + right: [
157 + " [=^・ω・^=]",
158 + " [=^˘ω˘^=]",
159 + " ▣[=^・ω・^=]",
160 + " ▥[=^・ω・^=]",
161 + ],
162 + },
163 + walking: {
164 + left: [
165 + "[~^・ω・^∿]▣ ",
166 + "[~^・ω・^∿]▥ ",
167 + "[~^・ω・^∿]< ",
168 + "[~^˘ω˘^∿]▥ ",
169 + ],
170 + right: [
171 + " ▣[∿^・ω・^~]",
172 + " ▥[∿^・ω・^~]",
173 + " >[∿^・ω・^~]",
174 + " ▥[∿^˘ω˘^~]",
175 + ],
176 + },
177 + },
179 + error: {
180 + idle: {
181 + left: [
182 + "(!^ಠωಠ^)!! ",
183 + "(!!ಠωಠ^)! ",
184 + "(!^ಠωಠ!!) ",
185 + "(!!ಠωಠ!!) ",
186 + ],
187 + right: [
188 + " !!(^ಠωಠ^!)",
189 + " !(^ಠωಠ!!)",
190 + " (!!ಠωಠ^!)",
191 + " (!!ಠωಠ!!)",
192 + ],
193 + },
194 + walking: {
195 + left: [
196 + "(!^ಠωಠ^∿)!!",
197 + "(!^ಠωಠ^∿)! ",
198 + "(!^ಠωಠ^∿)< ",
199 + "(!^ಠωಠ^∿)! ",
200 + ],
201 + right: [
202 + "!!(∿^ಠωಠ^!)",
203 + " !(∿^ಠωಠ^!)",
204 + " >(∿^ಠωಠ^!)",
205 + " !(∿^ಠωಠ^!)",
206 + ],
207 + },
208 + },
210 + sleeping: {
211 + idle: {
212 + left: [
213 + "(-˘ω˘-) z ",
214 + "(-˘ω˘-) z ",
215 + "(-˘ω˘-) Z ",
216 + "(-˘ω˘-) ",
217 + ],
218 + right: [
219 + " z (-˘ω˘-)",
220 + " z (-˘ω˘-)",
221 + " Z (-˘ω˘-)",
222 + " (-˘ω˘-)",
223 + ],
224 + },
225 + walking: {
226 + left: [
227 + "(-˘ω˘-∿)z ",
228 + "(-˘ω˘-∿)z ",
229 + "(-˘ω˘-∿)< ",
230 + "(-˘ω˘-∿) ",
231 + ],
232 + right: [
233 + " z(∿-˘ω˘-)",
234 + " z(∿-˘ω˘-)",
235 + " >(∿-˘ω˘-)",
236 + " (∿-˘ω˘-)",
237 + ],
238 + },
239 + },
242 +const FPS = Number(process.env.NEKO_PREVIEW_FPS ?? 8);
243 +const FRAME_MS = Math.max(40, Math.floor(1000 / FPS));
244 +const CYCLE_FRAMES = 24;
245 +const STRIP_ANSI = /\x1b\[[0-9;]*m/g;
247 +function color(activity: Activity, text: string): string {
248 + return `${ACTIVITY_COLOR[activity]}${text}${A.reset}`;
251 +function frameOf(activity: Activity, motion: Motion, facing: Facing, frame: number): string {
252 + const frames = SPRITES[activity][motion][facing];
253 + return color(activity, frames[frame % frames.length] ?? "");
256 +function displayWidth(text: string): number {
257 + return [...text.replace(STRIP_ANSI, "")].length;
260 +function pad(text: string, width: number): string {
261 + return text + " ".repeat(Math.max(0, width - displayWidth(text)));
264 +function render(frame: number): string {
265 + const lines: string[] = [];
266 + lines.push(`${A.bold}${A.cyan}neko sprite preview${A.reset} ${A.dim}| Ctrl-C quits | NEKO_PREVIEW_FPS=12 bun agent/extensions/neko-preview.ts${A.reset}`);
267 + lines.push("");
268 + lines.push(`${pad("activity", 12)} ${pad("idle ←", 18)} ${pad("idle →", 18)} ${pad("walk ←", 18)} ${pad("walk →", 18)}`);
269 + lines.push(`${A.dim}${"─".repeat(89)}${A.reset}`);
271 + for (const activity of ACTIVITY_ORDER) {
272 + const label = color(activity, pad(activity, 12));
273 + lines.push([
274 + label,
275 + pad(frameOf(activity, "idle", "left", frame), 18),
276 + pad(frameOf(activity, "idle", "right", frame), 18),
277 + pad(frameOf(activity, "walking", "left", frame), 18),
278 + pad(frameOf(activity, "walking", "right", frame), 18),
279 + ].join(" "));
282 + lines.push("");
283 + lines.push(`${A.dim}Design contract: activity + motion + facing + frame → sprite${A.reset}`);
284 + return lines.join("\n");
287 +let frame = 0;
289 +function draw(): void {
290 + process.stdout.write("\x1b[2J\x1b[3J\x1b[H\x1b[?25l");
291 + process.stdout.write(render(frame++));
294 +function cleanup(): never {
295 + process.stdout.write(`${A.reset}\x1b[?25h\n`);
296 + process.exit(0);
299 +process.on("SIGINT", cleanup);
300 +process.on("SIGTERM", cleanup);
302 +if (!process.stdout.isTTY) {
303 + for (let i = 0; i < CYCLE_FRAMES; i++) {
304 + if (i > 0) process.stdout.write(`\n${A.dim}${"─".repeat(89)}${A.reset}\n`);
305 + process.stdout.write(render(i));
307 + process.stdout.write("\n");
308 + process.exit(0);
311 +draw();
312 +setInterval(draw, FRAME_MS);