custom-header.ts 2.4 KB

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