dotfiles
bugabingas dorkfiles
owned by bugabinga
remove(pi): drop neko preview script
d9b5007366bbf8256c50089e5260de52f15ae385
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (1)
pi/agent/previews/neko-preview.ts
Deleteddeleted file mode 100644 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[]>>;
29 - magenta:
"\x1b[35m",
33 -const ACTIVITY_COLOR
: Record<
Activity,
string>
= {
37 - compacting: A.magenta,
42 -const ACTIVITY_ORDER
: Activity[]
= [
"normal",
"thinking",
"working",
"compacting",
"error",
"sleeping"];
46 -const SPRITES
: Record<
Activity,
SpriteSet>
= {
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/previews/neko-preview.ts${A.reset}`);
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));
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),
283 - lines.
push(
`${A.dim}Design contract: activity + motion + facing + frame → sprite${A.reset}`);
284 - return lines.
join(
"\n");
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`);
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");
312 -setInterval(draw, FRAME_MS);