repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

fix(pi/footer): swap footer via setFooter() on toggle for true 0-height when hidden

a49441f4e1e4649ba95c2124b166524e51bec9dc

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (2)

pi/agent/extensions/footer/index.ts

Modified
10 10 * Producers use semantic zones ("workspace" | "llm"). Footer decides row mapping.
11 11 * Uses setFooter() — the single footer owner. Producers are decoupled.
12 + *
13 + * /footer or ctrl+alt+f toggles visibility by swapping between
14 + * the real footer and a zero-height stub via setFooter().
14 17 import type { ExtensionAPI, ExtensionContext, Theme, ThemeColor } from "@mariozechner/pi-coding-agent";
45 48 barWidth: 10,
51 +/** Zero-height footer stub for hidden mode. */
52 +const HIDDEN_FOOTER = {
53 + dispose: () => {},
54 + invalidate() {},
55 + render(): string[] { return []; },
56 +};
48 58 export default function footerExtension(pi: ExtensionAPI) {
49 59 const segments = new Map<string, Segment>();
50 60 let config: FooterConfig = { ...DEFAULT_CONFIG };
51 61 let requestRender: (() => void) | undefined;
52 62 let renderScheduled = false;
53 63 let hidden = false;
64 + let currentCtx: ExtensionContext | undefined;
55 66 // ── Event listener ────────────────────────────────────────────────
89 - // ── Render ────────────────────────────────────────────────────────
100 + // ── Render helpers ────────────────────────────────────────────────
91 102 function getZoneSegments(zone: FooterZone, ctx?: ExtensionContext): Segment[] {
92 103 const segs = Array.from(segments.values()).filter((s) => s.zone === zone);
93 104 if (zone === "workspace" && ctx) {
94 - // Session name is Pi-owned state, not an extension-owned producer segment.
95 - // `pi.setSessionName()` emits core `session_info_changed` to interactive mode,
96 - // which already requests a render; that event is not part of the extension
97 - // lifecycle/event-bus surface. Read it live here so /name, session-rename,
98 - // resume, and any future core setter all update without a footer:segment emit.
99 105 const name = getSessionName(ctx);
100 106 if (name) {
101 107 segs.push({ id: "session-name", text: name, icon: "✎", color: "accent", zone: "workspace", order: 0.5 });
119 125 const bar = config.barStyle === "blocks"
120 126 ? renderBlocksBar(seg.bar, config.barWidth, theme, color)
121 127 : renderContinuousBar(seg.bar, config.barWidth, theme, color);
122 - // Attach suffix directly to bar (no gap)
123 128 const suffix = seg.suffix ? theme.fg(color, seg.suffix) : "";
124 129 parts.push(bar + suffix);
125 130 } else if (seg.suffix) {
171 176 return [line1, line2];
174 - // ── Toggle ────────────────────────────────────────────────────────
179 + // ── Footer mounting ───────────────────────────────────────────────
176 - function toggleVisibility(ctx: ExtensionContext) {
177 - hidden = !hidden;
178 - ctx.ui.notify(hidden ? "Footer hidden" : "Footer visible", "info");
179 - scheduleRender();
180 - }
181 + function mountFooter() {
182 + if (!currentCtx) return;
182 - pi.registerCommand("footer", {
183 - description: "Toggle footer visibility",
184 - handler: async (_args, ctx) => toggleVisibility(ctx),
185 - });
184 + if (hidden) {
185 + requestRender = undefined;
186 + currentCtx.ui.setFooter(() => HIDDEN_FOOTER);
187 + return;
187 - pi.registerShortcut(Key.ctrlAlt("f"), {
188 - description: "Toggle footer visibility",
189 - handler: async (ctx) => toggleVisibility(ctx),
190 - });
192 - // ── Lifecycle ─────────────────────────────────────────────────────
194 - pi.on("session_start", async (_event, ctx) => {
195 - if (!ctx.hasUI) return;
197 - ctx.ui.setFooter((tui, theme, footerData) => {
190 + currentCtx.ui.setFooter((tui, theme, footerData) => {
198 191 requestRender = () => tui.requestRender();
199 192 const unsubBranch = footerData.onBranchChange(() => scheduleRender());
206 199 invalidate() {},
207 200 render(width: number): string[] {
208 - if (hidden) return [];
210 201 const contentWidth = Math.max(0, width - 2);
211 202 const padLine = (line: string) => {
212 203 if (width <= 1) return truncateToWidth(line, width);
213 204 return ` ${truncateToWidth(line, contentWidth)} `;
216 - const workspaceLine = renderWorkspaceLine(theme, contentWidth, ctx);
207 + const workspaceLine = renderWorkspaceLine(theme, contentWidth, currentCtx!);
217 208 const [llmLine1, llmLine2] = renderLlmLines(theme, contentWidth);
219 210 // Extension statuses (3rd party, via setStatus)
241 - // Force initial render of any segments that were emitted during
242 - // other extensions' session_start (before our setFooter ran)
232 + // Force render of segments emitted before mount
243 233 setTimeout(() => scheduleRender(), 0);
236 + // ── Toggle ────────────────────────────────────────────────────────
238 + function toggleVisibility(ctx: ExtensionContext) {
239 + hidden = !hidden;
240 + currentCtx = ctx;
241 + ctx.ui.notify(hidden ? "Footer hidden" : "Footer visible", "info");
242 + mountFooter();
245 + pi.registerCommand("footer", {
246 + description: "Toggle footer visibility",
247 + handler: async (_args, ctx) => toggleVisibility(ctx),
248 + });
250 + pi.registerShortcut(Key.ctrlAlt("f"), {
251 + description: "Toggle footer visibility",
252 + handler: async (ctx) => toggleVisibility(ctx),
253 + });
255 + // ── Lifecycle ─────────────────────────────────────────────────────
257 + pi.on("session_start", async (_event, ctx) => {
258 + if (!ctx.hasUI) return;
259 + currentCtx = ctx;
260 + mountFooter();
246 263 pi.on("session_shutdown", async () => {
247 264 segments.clear();
248 265 requestRender = undefined;
266 + currentCtx = undefined;

pi/agent/previews/neko-preview.ts

Modified
3 3 #!/usr/bin/env bun
5 5 * Standalone neko sprite preview.
7 7 * Run in a real terminal:
8 - * bun agent/extensions/neko-preview.ts
8 + * bun agent/previews/neko-preview.ts
10 10 * Faster/slower:
11 - * NEKO_PREVIEW_FPS=12 bun agent/extensions/neko-preview.ts
11 + * NEKO_PREVIEW_FPS=12 bun agent/previews/neko-preview.ts
13 13 * Captured/non-TTY output prints one finite animation cycle.
264 264 function render(frame: number): string {
265 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}`);
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}`);
267 267 lines.push("");
268 268 lines.push(`${pad("activity", 12)} ${pad("idle ←", 18)} ${pad("idle →", 18)} ${pad("walk ←", 18)} ${pad("walk →", 18)}`);
269 269 lines.push(`${A.dim}${"─".repeat(89)}${A.reset}`);