forked from badlogic/pi-mono
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-header.ts
More file actions
73 lines (62 loc) · 2.34 KB
/
custom-header.ts
File metadata and controls
73 lines (62 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Custom Header Extension
*
* Demonstrates ctx.ui.setHeader() for replacing the built-in header
* (logo + keybinding hints) with a custom component showing the pi mascot.
*/
import type { ExtensionAPI, Theme } from "@mariozechner/pi-coding-agent";
import { VERSION } from "@mariozechner/pi-coding-agent";
// --- PI MASCOT ---
// Based on pi_mascot.ts - the pi agent character
function getPiMascot(theme: Theme): string[] {
// --- COLORS ---
// 3b1b Blue: R=80, G=180, B=230
const piBlue = (text: string) => theme.fg("accent", text);
const white = (text: string) => text; // Use plain white (or theme.fg("text", text))
const black = (text: string) => theme.fg("dim", text); // Use dim for contrast
// --- GLYPHS ---
const BLOCK = "█";
const PUPIL = "▌"; // Vertical half-block for the pupil
// --- CONSTRUCTION ---
// 1. The Eye Unit: [White Full Block][Black Vertical Sliver]
// This creates the "looking sideways" effect
const eye = `${white(BLOCK)}${black(PUPIL)}`;
// 2. Line 1: The Eyes
// 5 spaces indent aligns them with the start of the legs
const lineEyes = ` ${eye} ${eye}`;
// 3. Line 2: The Wide Top Bar (The "Overhang")
// 14 blocks wide for that serif-style roof
const lineBar = ` ${piBlue(BLOCK.repeat(14))}`;
// 4. Lines 3-6: The Legs
// Indented 5 spaces relative to the very left edge
// Leg width: 2 blocks | Gap: 4 blocks
const lineLeg = ` ${piBlue(BLOCK.repeat(2))} ${piBlue(BLOCK.repeat(2))}`;
// --- ASSEMBLY ---
return ["", lineEyes, lineBar, lineLeg, lineLeg, lineLeg, lineLeg, ""];
}
export default function (pi: ExtensionAPI) {
// Set custom header immediately on load (if UI is available)
pi.on("session_start", async (_event, ctx) => {
if (ctx.hasUI) {
ctx.ui.setHeader((_tui, theme) => {
return {
render(_width: number): string[] {
const mascotLines = getPiMascot(theme);
// Add a subtitle with hint
const subtitle = `${theme.fg("muted", " shitty coding agent")}${theme.fg("dim", ` v${VERSION}`)}`;
return [...mascotLines, subtitle];
},
invalidate() {},
};
});
}
});
// Command to restore built-in header
pi.registerCommand("builtin-header", {
description: "Restore built-in header with keybinding hints",
handler: async (_args, ctx) => {
ctx.ui.setHeader(undefined);
ctx.ui.notify("Built-in header restored", "info");
},
});
}