Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(office): coding desk monitors show the agent's pane the way the IDE draws it

rubenluetke10-beep0df8a4b4c36a
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgentMark.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgentMark.tsx
index 41f77df5cd..344f1d03c0 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgentMark.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgentMark.tsx
@@ -44,6 +44,14 @@ const AGENT_LOGOS: Record<string, LogoAsset> = {
opencode: { url: "/agent-logos/opencode.svg", ground: "dark" },
};
+/**
+ * The shipped brand file for an agent and the ground it needs, or null for an
+ * agent without one. For drawing the mark where no DOM exists (a canvas).
+ */
+export function agentLogoAsset(agent: string): { url: string; ground: LogoGround } | null {
+ return AGENT_LOGOS[agent] ?? null;
+}
+
interface AgentMarkProps {
agent: string;
label: string;
diff --git a/jarvis/ui/web/frontend/src/components/society/office/TerminalMonitors.tsx b/jarvis/ui/web/frontend/src/components/society/office/TerminalMonitors.tsx
index b43ba990d8..a2bccd884b 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/TerminalMonitors.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/TerminalMonitors.tsx
@@ -1,15 +1,22 @@
/**
- * Desk monitors on the coding floor: each shows its pane's terminal live
- * while the agent sits at the desk, a dim screensaver otherwise. A click on a
+ * Desk monitors on the coding floor: each shows its pane live, drawn as the
+ * Agentic IDE draws it — the pane's header (status, CLI mark, title, what it is
+ * doing) over its terminal in the IDE's font and colours — while the agent
+ * sits at the desk, and the header over a quiet screen otherwise. A click on a
* screen opens that agent's command panel, where it can be prompted.
*/
import { useEffect, useMemo, useRef, useState } from "react";
import { useFrame, type ThreeEvent } from "@react-three/fiber";
import { CanvasTexture, SRGBColorSpace } from "three";
+import { useT } from "@/i18n";
+import { useThemeValue } from "@/hooks/useTheme";
import type { PaneScreen } from "@/lib/paneScreensApi";
+import { usePaneTitle } from "@/store/paneRecaps";
+import { storedTerminalAppearance } from "@/components/agentic/terminalThemes";
import type { DeskSlot, Point } from "./officeLayout";
import type { PaneOccupant } from "./codingFloor";
-import { drawTerminalScreen, paneDot, TERMINAL_H, TERMINAL_W } from "./terminalScreen";
+import { drawTerminalScreen, monitorPalette, paneDot, TERMINAL_H, TERMINAL_W, type MonitorPalette } from "./terminalScreen";
+import { useAgentMark } from "./monitorMarks";
import { MAX_SCREEN_TARGETS, usePaneScreens, type PaneScreenTarget } from "./usePaneScreens";
import { seatedAtDesk } from "./walkerRegistry";
@@ -17,14 +24,30 @@ import { seatedAtDesk } from "./walkerRegistry";
const SCREEN_Y = 1.18, SCREEN_Z = -0.2095, SCREEN_W = 0.66, SCREEN_H = 0.38;
/** How often the nearest-seated set is re-read, in seconds. */
const NEAR_CHECK_S = 0.4;
+/** The "for 3 min" in the headers moves on this clock. */
+const META_TICK_MS = 30_000;
+
+/** "Working · 3 min": the pane's state and how long it has held it at `nowMs`, as the IDE header says it. */
+function useMeta(occupant: PaneOccupant, nowMs: number): string {
+ const t = useT();
+ const state = t(`society.office.pane_state_${occupant.stateKey}`);
+ const at = occupant.pane.activity_since;
+ if (!at) return state;
+ const seconds = Math.max(0, nowMs / 1000 - at);
+ const since = seconds < 60 ? t("society.office.since_now")
+ : seconds < 3600 ? t("society.office.since_minutes").replace("{0}", String(Math.floor(seconds / 60)))
+ : seconds < 86400 ? t("society.office.since_hours").replace("{0}", String(Math.floor(seconds / 3600)))
+ : t("society.office.since_days").replace("{0}", String(Math.floor(seconds / 86400)));
+ return `${state} · ${since}`;
+}
/** The nearest seated agents to the camera, at most `limit`, as a sorted id list. Pure. */
export function nearestSeated(candidates: { id: string; distance: number }[], limit = MAX_SCREEN_TARGETS): string[] {
return [...candidates].sort((a, b) => a.distance - b.distance).slice(0, limit).map((c) => c.id).sort();
}
-function Screen({ desk, occupant, screen, onOpen }: {
- desk: DeskSlot; occupant: PaneOccupant; screen: PaneScreen | undefined;
+function Screen({ desk, occupant, screen, palette, nowMs, onOpen }: {
+ desk: DeskSlot; occupant: PaneOccupant; screen: PaneScreen | undefined; palette: MonitorPalette; nowMs: number;
onOpen: (agentId: string, screen: Point & { y: number }, facing: number) => void;
}) {
const hovered = useRef(false);
@@ -45,14 +68,18 @@ function Screen({ desk, occupant, screen, onOpen }: {
surface?.texture.dispose();
if (hovered.current) document.body.style.cursor = "";
}, [surface]);
- const name = occupant.agent.name;
- const dot = paneDot(occupant.pane);
+ const { pane } = occupant;
+ // The header reads exactly like the pane's IDE header: its title, else its topic, else the agent.
+ const title = usePaneTitle(pane.workspace_id, pane.name) || pane.recap.trim() || occupant.agent.name;
+ const meta = useMeta(occupant, nowMs);
+ const mark = useAgentMark(pane.agent, palette.ink);
+ const dot = paneDot(pane);
const shown = seated ? screen : undefined;
useEffect(() => {
if (!surface) return;
- drawTerminalScreen(surface.ctx, { name, dot }, shown);
+ drawTerminalScreen(surface.ctx, { title, meta, dot, mark, palette }, shown);
surface.texture.needsUpdate = true;
- }, [surface, name, dot, shown]);
+ }, [surface, title, meta, dot, mark, palette, shown]);
// Seating is a per-frame module set; only its flips reach React.
useFrame(() => {
const now = seatedAtDesk.has(agentId);
@@ -100,12 +127,22 @@ export function TerminalMonitors({ desks, occupants, awake, onOpen }: {
return pane ? [{ agentId, workspaceId: pane.workspace_id, key: pane.key }] : [];
}), [near, occupants]);
const screens = usePaneScreens(targets, awake);
+ // The IDE's pane appearance: the reader's stored choice, else the app's theme.
+ const appTheme = useThemeValue();
+ const appearance = storedTerminalAppearance() ?? appTheme;
+ const palette = useMemo(() => monitorPalette(appearance), [appearance]);
+ const [nowMs, setNowMs] = useState(() => Date.now());
+ useEffect(() => {
+ const timer = setInterval(() => setNowMs(Date.now()), META_TICK_MS);
+ return () => clearInterval(timer);
+ }, []);
return (
<group>
{desks.map((desk) => {
const occupant = desk.agentId ? occupants.get(desk.agentId) : undefined;
return occupant
- ? <Screen key={desk.id} desk={desk} occupant={occupant} screen={screens.get(occupant.agent.agentId)} onOpen={onOpen} />
+ ? <Screen key={desk.id} desk={desk} occupant={occupant} screen={screens.get(occupant.agent.agentId)}
+ palette={palette} nowMs={nowMs} onOpen={onOpen} />
: null;
})}
</group>
diff --git a/jarvis/ui/web/frontend/src/components/society/office/monitorMarks.ts b/jarvis/ui/web/frontend/src/components/society/office/monitorMarks.ts
new file mode 100644
index 0000000000..73a1a2981b
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/office/monitorMarks.ts
@@ -0,0 +1,77 @@
+/**
+ * The CLI marks the desk monitors draw in their title bar, as bitmaps.
+ *
+ * A canvas cannot use AgentMark (a DOM component), so the same shipped brand
+ * file is loaded once per agent and ink, and rendered the way AgentMark shows
+ * it: an `ink` silhouette tinted with the pane's ink, a `dark` lockup on its
+ * dark tile, an `any` lockup as it is. Until a mark has loaded — or when an
+ * agent has none — the monitor draws the terminal glyph instead.
+ */
+import { useEffect, useState } from "react";
+import { agentLogoAsset } from "@/components/agentic/AgentMark";
+
+const SIZE = 64;
+const marks = new Map<string, HTMLCanvasElement>();
+const pending = new Map<string, Promise<HTMLCanvasElement | null>>();
+const failedUrls = new Set<string>();
+
+function render(image: HTMLImageElement, ground: "ink" | "dark" | "any", ink: string): HTMLCanvasElement | null {
+ const canvas = document.createElement("canvas");
+ canvas.width = SIZE; canvas.height = SIZE;
+ const ctx = canvas.getContext("2d");
+ if (!ctx) return null;
+ if (ground === "dark") {
+ ctx.fillStyle = "#18181b";
+ ctx.beginPath(); ctx.roundRect(0, 0, SIZE, SIZE, 12); ctx.fill();
+ ctx.drawImage(image, 8, 8, SIZE - 16, SIZE - 16);
+ return canvas;
+ }
+ ctx.drawImage(image, 0, 0, SIZE, SIZE);
+ if (ground === "ink") {
+ // The silhouette takes the pane's ink, the way AgentMark masks it over the text colour.
+ ctx.globalCompositeOperation = "source-in";
+ ctx.fillStyle = ink;
+ ctx.fillRect(0, 0, SIZE, SIZE);
+ }
+ return canvas;
+}
+
+function load(agent: string, ink: string): Promise<HTMLCanvasElement | null> {
+ const asset = agentLogoAsset(agent);
+ if (!asset || failedUrls.has(asset.url) || typeof document === "undefined") return Promise.resolve(null);
+ const key = `${agent}|${ink}`;
+ const known = pending.get(key);
+ if (known) return known;
+ const promise = new Promise<HTMLCanvasElement | null>((resolve) => {
+ const image = new Image(SIZE, SIZE);
+ image.onload = () => {
+ const canvas = render(image, asset.ground, ink);
+ if (canvas) marks.set(key, canvas);
+ resolve(canvas);
+ };
+ image.onerror = () => {
+ // The monitor keeps its terminal glyph; one line per broken file, never a retry loop.
+ failedUrls.add(asset.url);
+ console.warn(`Office monitor: the ${agent} mark could not be loaded from ${asset.url}`);
+ resolve(null);
+ };
+ image.src = asset.url;
+ });
+ pending.set(key, promise);
+ return promise;
+}
+
+/** The agent's mark tinted for `ink`, or null until it has loaded (or when there is none). */
+export function useAgentMark(agent: string, ink: string): HTMLCanvasElement | null {
+ const key = `${agent}|${ink}`;
+ const [mark, setMark] = useState<HTMLCanvasElement | null>(() => marks.get(key) ?? null);
+ useEffect(() => {
+ const ready = marks.get(key);
+ if (ready) { setMark(ready); return; }
+ let alive = true;
+ setMark(null);
+ void load(agent, ink).then((canvas) => { if (alive) setMark(canvas); });
+ return () => { alive = false; };
+ }, [agent, ink, key]);
+ return mark;
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/office/terminalScreen.test.ts b/jarvis/ui/web/frontend/src/components/society/office/terminalScreen.test.ts
index 320d021a8a..049adb7530 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/terminalScreen.test.ts
+++ b/jarvis/ui/web/frontend/src/components/society/office/terminalScreen.test.ts
@@ -1,7 +1,8 @@
import { describe, expect, it } from "vitest";
import type { PaneScreen } from "@/lib/paneScreensApi";
import {
- drawTerminalScreen, paneDot, screenChanged, terminalLayout, truncateRow, visibleRows,
+ drawTerminalScreen, monitorPalette, paneDot, rowTones, screenChanged, terminalLayout, truncateRow, visibleRows,
+ type MonitorFace,
} from "./terminalScreen";
/** A 2D context that records what was drawn. */
@@ -12,7 +13,7 @@ function recordingContext() {
fillStyle: "", font: "", textAlign: "start", textBaseline: "alphabetic",
fillRect(x: number, y: number, w: number, h: number) { rects.push({ x, y, w, h, fill: String(this.fillStyle) }); },
fillText(text: string, x: number, y: number) { texts.push({ text, x, y, fill: String(this.fillStyle) }); },
- beginPath() {}, arc() {}, fill() {},
+ beginPath() {}, arc() {}, fill() {}, drawImage() {},
measureText(text: string) { return { width: text.length * 8 }; },
};
return { ctx: ctx as unknown as CanvasRenderingContext2D, texts, rects };
@@ -34,12 +35,20 @@ describe("terminal monitor layout", () => {
it("draws nothing but the cursor row for an empty screen", () => {
expect(visibleRows(["", " "], 5, null)).toEqual({ rows: [], first: 0 });
});
- it("shrinks the font for wide terminals within bounds", () => {
- const narrow = terminalLayout(40), wide = terminalLayout(200);
+ it("fits the font to the terminal's width, within bounds", () => {
+ const narrow = terminalLayout(37), wide = terminalLayout(200);
expect(narrow.font).toBeGreaterThan(wide.font);
- expect(wide.font).toBeGreaterThanOrEqual(9);
- expect(narrow.font).toBeLessThanOrEqual(15);
+ expect(wide.font).toBeGreaterThanOrEqual(12);
+ expect(narrow.font).toBeLessThanOrEqual(40);
expect(wide.fit).toBeGreaterThan(narrow.fit);
+ // A narrow TUI fills the monitor instead of hugging its left edge.
+ expect(narrow.cols).toBeLessThan(60);
+ });
+ it("tones the TUI's rules and the status bar under the composer", () => {
+ const rows = ["answer", "────────────", "> prompt", "────────────", "status bar", "mode"];
+ expect(rowTones(rows)).toEqual(["text", "rule", "text", "rule", "status", "status"]);
+ // A separator high up in the output never mutes what follows it.
+ expect(rowTones(["────────────", "a", "b", "c"])).toEqual(["rule", "text", "text", "text"]);
});
it("cuts long rows with an ellipsis", () => {
expect(truncateRow("abcdef", 4)).toBe("abc…");
@@ -69,31 +78,47 @@ describe("terminal monitor state", () => {
});
});
+const face = (over: Partial<MonitorFace> = {}): MonitorFace => ({
+ title: "Refactor auth", meta: "Working · 3 min", dot: "working", mark: null, palette: monitorPalette("dark"), ...over,
+});
+
describe("terminal monitor drawing", () => {
- it("draws the title, the last rows and a cursor block", () => {
+ it("draws the IDE header, the last rows and a cursor block", () => {
const { ctx, texts, rects } = recordingContext();
const lines = Array.from({ length: 40 }, (_, i) => `line ${i}`);
- drawTerminalScreen(ctx, { name: "Refactor auth", dot: "working" }, screen({ lines, cursor: [39, 7] }));
- expect(texts[0].text).toBe("Refactor auth");
- const body = texts.slice(1).map((t) => t.text);
+ drawTerminalScreen(ctx, face(), screen({ lines, cursor: [39, 7] }));
+ const drawn = texts.map((t) => t.text);
+ expect(drawn).toContain("Refactor auth");
+ expect(drawn).toContain("Working · 3 min");
+ // No mark loaded yet: the terminal glyph stands in.
+ expect(drawn).toContain(">_");
+ const body = texts.filter((t) => t.text.startsWith("line ")).map((t) => t.text);
expect(body.at(-1)).toBe("line 39");
expect(body).not.toContain("line 0");
- // Background, title bar, cursor block.
- expect(rects).toHaveLength(3);
- const cursor = rects[2];
- expect(cursor.y).toBeGreaterThan(texts.at(-2)!.y);
+ const cursor = rects.at(-1)!;
+ expect(cursor.fill).toBe(monitorPalette("dark").cursor);
+ expect(cursor.y).toBeGreaterThan(texts.filter((t) => t.text.startsWith("line ")).at(-2)!.y);
+ });
+ it("draws the text in the pane's own ink for either appearance", () => {
+ for (const appearance of ["light", "dark"] as const) {
+ const { ctx, texts } = recordingContext();
+ drawTerminalScreen(ctx, face({ palette: monitorPalette(appearance) }), screen({ lines: ["hello"] }));
+ expect(texts.find((t) => t.text === "hello")?.fill).toBe(monitorPalette(appearance).text);
+ }
+ expect(monitorPalette("light").ground).not.toBe(monitorPalette("dark").ground);
});
it("truncates rows wider than the monitor", () => {
const { ctx, texts } = recordingContext();
- drawTerminalScreen(ctx, { name: "x", dot: "idle" }, screen({ cols: 240, lines: ["y".repeat(240)] }));
- expect(texts[1].text.endsWith("…")).toBe(true);
- expect(texts[1].text.length).toBe(terminalLayout(240).cols);
+ drawTerminalScreen(ctx, face(), screen({ cols: 240, lines: ["y".repeat(240)] }));
+ const row = texts.find((t) => t.text.startsWith("yyy"))!;
+ expect(row.text.endsWith("…")).toBe(true);
+ expect(row.text.length).toBe(terminalLayout(240).cols);
});
- it("shows a dim screensaver when no screen has arrived", () => {
- const { ctx, texts, rects } = recordingContext();
- drawTerminalScreen(ctx, { name: "Quiet pane", dot: "idle" }, undefined);
- expect(rects).toHaveLength(1);
- expect(texts.map((t) => t.text)).toEqual(["Quiet pane", ">_"]);
+ it("keeps the header over a quiet screen when no screen has arrived", () => {
+ const { ctx, texts } = recordingContext();
+ drawTerminalScreen(ctx, face({ title: "Quiet pane", dot: "idle" }), undefined);
+ expect(texts.map((t) => t.text)).toContain("Quiet pane");
+ expect(texts.at(-1)?.text).toBe(">_");
expect(ctx.textAlign).toBe("start");
});
});
diff --git a/jarvis/ui/web/frontend/src/components/society/office/terminalScreen.ts b/jarvis/ui/web/frontend/src/components/society/office/terminalScreen.ts
index 9e09844e4f..25b58f1fc3 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/terminalScreen.ts
+++ b/jarvis/ui/web/frontend/src/components/society/office/terminalScreen.ts
@@ -1,36 +1,88 @@
/**
- * A coding agent's desk monitor, drawn like a real terminal on a 2D canvas.
+ * A coding agent's desk monitor, drawn the way the Agentic IDE draws a pane.
*
- * Pure drawing and layout: the caller owns the canvas and the texture. The
- * screen text arrives with ANSI already stripped server-side; TUIs keep their
+ * The same title bar (status dot, the CLI's mark, the pane's title, what it is
+ * doing and for how long, the quiet action icons on the right) over the same
+ * terminal: the pane's own font, weight, ground and ink from the IDE's
+ * appearance tables, so a light IDE gets light monitors and a dark one dark.
+ * The font is fitted to the terminal's column count, the way the IDE fits its
+ * pane, so a narrow TUI fills the monitor instead of hugging its left edge.
+ *
+ * Pure drawing and layout: the caller owns the canvas, the texture and the
+ * logo bitmap. The screen text arrives with ANSI already stripped server-side
+ * (the screen feed replays layout, not colour), so the rows are drawn in the
+ * pane's ink; only the TUI's structure is toned — its rules and the status
+ * bar under the composer read muted, as the CLIs draw them. TUIs keep their
* composer at the bottom, so the monitor shows the bottom block that fits.
*/
import type { PaneScreen } from "@/lib/paneScreensApi";
import type { WorkspacePaneRow } from "@/lib/agenticIdeApi";
+import { TERMINAL_FONT_STACK, TERMINAL_FONT_WEIGHT } from "@/lib/terminalFont";
+import { PANE_BRAND, PANE_CHROME, themeFor, type TerminalAppearance } from "@/components/agentic/terminalThemes";
/** Canvas size in pixels; the aspect matches the 0.66 x 0.38 m screen plane. */
-export const TERMINAL_W = 768, TERMINAL_H = 442;
+export const TERMINAL_W = 1024, TERMINAL_H = 590;
-const TITLE_H = 40;
-const PAD = 10;
+/** The title bar: the IDE's 36 px header, scaled to the monitor. */
+const TITLE_H = 56;
+const PAD = 16;
/** Font size bounds: a wide TUI shrinks the text, a narrow one never blows it up. */
-const MIN_FONT = 9, MAX_FONT = 15;
+const MIN_FONT = 12, MAX_FONT = 40;
/** Wider terminals than this are cut on the right rather than shrunk further. */
-const MAX_FIT_COLS = 110;
-const MONO = "ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace";
-const SANS = "system-ui, -apple-system, 'Segoe UI', sans-serif";
+const MAX_FIT_COLS = 120;
+const SANS = "Inter, system-ui, -apple-system, 'Segoe UI', sans-serif";
/** A monospace glyph is about this wide per pixel of font size. */
const CHAR_RATIO = 0.6;
-const LINE_RATIO = 1.25;
+const LINE_RATIO = 1.2;
+/** The header's action icons, right to left: close, add, maximize, more. */
+const ICONS = ["×", "+", "⤢", "⋯"];
+const ICON_STEP = 40;
export type ScreenDot = "working" | "asking" | "idle" | "error";
-const DOT_COLOUR: Record<ScreenDot, string> = {
- working: "#4ade80",
- asking: "#fbbf24",
- idle: "#94a3b8",
- error: "#f87171",
-};
+/** Every colour a monitor uses, resolved for one pane appearance. */
+export interface MonitorPalette {
+ ground: string;
+ rule: string;
+ ink: string;
+ inkMuted: string;
+ inkFaint: string;
+ /** The terminal's own foreground and cursor. */
+ text: string;
+ cursor: string;
+ dot: Record<ScreenDot, string>;
+}
+
+/** The pane's opaque ground: PANE_SOLID without its alpha, since a monitor has nothing behind it. */
+const GROUND: Record<TerminalAppearance, string> = { light: "#fcfbf8", dark: "#121212" };
+
+/** The IDE's pane colours for `appearance`. Pure. */
+export function monitorPalette(appearance: TerminalAppearance): MonitorPalette {
+ const brand = PANE_BRAND[appearance], chrome = PANE_CHROME[appearance], ansi = themeFor(appearance);
+ return {
+ ground: GROUND[appearance],
+ rule: chrome.border,
+ ink: brand.ink,
+ inkMuted: brand.inkMuted,
+ inkFaint: brand.inkFaint,
+ text: ansi.foreground ?? brand.ink,
+ cursor: ansi.cursor ?? brand.ink,
+ // The header dot reads like the IDE's: live green, asking yellow, failed red, idle faint.
+ dot: { working: ansi.green ?? "#4ade80", asking: ansi.yellow ?? "#fbbf24", error: ansi.red ?? "#f87171", idle: brand.inkFaint },
+ };
+}
+
+/** What the title bar says about the pane. */
+export interface MonitorFace {
+ /** The pane's title, as its IDE header shows it. */
+ title: string;
+ /** What it is doing and for how long ("Working · 3 min"); may be empty. */
+ meta: string;
+ dot: ScreenDot;
+ /** The CLI's mark, already tinted for the ground; null draws the terminal glyph. */
+ mark: CanvasImageSource | null;
+ palette: MonitorPalette;
+}
/** The title-bar dot for a pane, the same reading the grid's badge gives. */
export function paneDot(pane: Pick<WorkspacePaneRow, "status" | "activity">): ScreenDot {
@@ -57,7 +109,7 @@ export interface TerminalLayout {
fit: number;
}
-/** Font and grid for a terminal `cols` wide on the monitor. Pure. */
+/** Font and grid for a terminal `cols` wide on the monitor: fitted to the width, like the IDE's pane. Pure. */
export function terminalLayout(cols: number): TerminalLayout {
const want = Math.max(20, Math.min(cols || 80, MAX_FIT_COLS));
const font = Math.max(MIN_FONT, Math.min(MAX_FONT, Math.floor((TERMINAL_W - 2 * PAD) / (want * CHAR_RATIO))));
@@ -90,63 +142,126 @@ export function truncateRow(row: string, cols: number): string {
return row.length > cols ? `${row.slice(0, Math.max(0, cols - 1))}…` : row;
}
-function titleBar(ctx: CanvasRenderingContext2D, name: string, dot: ScreenDot): void {
- ctx.fillStyle = "#161b24";
+/** A row the TUI draws as a horizontal rule (the composer's frame). Pure. */
+export function isRuleRow(row: string): boolean {
+ const text = row.trim();
+ return text.length >= 8 && /^[─━═╌┄-]+$/.test(text);
+}
+
+/**
+ * How each shown row is toned: "rule" for the TUI's frame lines, "status" for
+ * the bar under the composer (everything after the last rule), "text" for the
+ * rest. Only a rule in the lower half starts a status bar, so a separator in
+ * the middle of the output never mutes the answer under it. Pure.
+ */
+export function rowTones(rows: readonly string[]): ("text" | "rule" | "status")[] {
+ let last = -1;
+ rows.forEach((row, i) => { if (isRuleRow(row)) last = i; });
+ const statusFrom = last >= rows.length / 2 ? last + 1 : rows.length;
+ return rows.map((row, i) => (isRuleRow(row) ? "rule" : i >= statusFrom ? "status" : "text"));
+}
+
+/** `text` cut with an ellipsis so it fits `max` pixels in the current font. */
+function fitText(ctx: CanvasRenderingContext2D, text: string, max: number): string {
+ if (max <= 0) return "";
+ if (ctx.measureText(text).width <= max) return text;
+ let lo = 0, hi = text.length;
+ while (lo < hi) {
+ const mid = Math.ceil((lo + hi) / 2);
+ if (ctx.measureText(`${text.slice(0, mid)}…`).width <= max) lo = mid; else hi = mid - 1;
+ }
+ return `${text.slice(0, lo)}…`;
+}
+
+function mark(ctx: CanvasRenderingContext2D, face: MonitorFace, x: number, size: number): void {
+ const y = (TITLE_H - size) / 2;
+ if (face.mark) {
+ ctx.drawImage(face.mark, x, y, size, size);
+ return;
+ }
+ ctx.fillStyle = face.palette.inkMuted;
+ ctx.font = `${TERMINAL_FONT_WEIGHT} ${Math.round(size * 0.8)}px ${TERMINAL_FONT_STACK}`;
+ ctx.fillText(">_", x, TITLE_H / 2 + 1);
+}
+
+/** The IDE's pane header: dot, mark, title, what it is doing, and the action icons. */
+function titleBar(ctx: CanvasRenderingContext2D, face: MonitorFace): void {
+ const { palette } = face;
+ ctx.fillStyle = palette.ground;
ctx.fillRect(0, 0, TERMINAL_W, TITLE_H);
- ctx.fillStyle = DOT_COLOUR[dot];
- ctx.beginPath(); ctx.arc(20, TITLE_H / 2, 7, 0, Math.PI * 2); ctx.fill();
- ctx.fillStyle = "#e5e7eb";
- ctx.font = `600 19px ${SANS}`;
+ ctx.fillStyle = palette.rule;
+ ctx.fillRect(0, TITLE_H - 2, TERMINAL_W, 2);
ctx.textBaseline = "middle";
- ctx.fillText(truncateRow(name, 52), 36, TITLE_H / 2 + 1);
+ ctx.textAlign = "left";
+ ctx.fillStyle = palette.dot[face.dot];
+ ctx.beginPath(); ctx.arc(24, TITLE_H / 2, 5, 0, Math.PI * 2); ctx.fill();
+ mark(ctx, face, 40, 26);
+ // Icons first, so the title knows where it has to stop.
+ ctx.fillStyle = palette.inkMuted;
+ ctx.font = `400 26px ${SANS}`;
+ ctx.textAlign = "center";
+ ICONS.forEach((icon, i) => ctx.fillText(icon, TERMINAL_W - 26 - i * ICON_STEP, TITLE_H / 2 + 1));
+ ctx.textAlign = "left";
+ const left = 80, right = TERMINAL_W - 26 - ICONS.length * ICON_STEP;
+ ctx.font = `500 22px ${SANS}`;
+ // The title yields to the meta text up to 40 % of the bar, never more.
+ const metaW = face.meta ? Math.min(ctx.measureText(face.meta).width, (right - left) * 0.4) : 0;
+ const title = fitText(ctx, face.title, right - left - (metaW ? metaW + 16 : 0));
+ ctx.fillStyle = palette.ink;
+ ctx.fillText(title, left, TITLE_H / 2 + 1);
+ if (face.meta) {
+ const titleW = ctx.measureText(title).width;
+ ctx.font = `400 19px ${SANS}`;
+ ctx.fillStyle = palette.inkMuted;
+ ctx.fillText(fitText(ctx, face.meta, right - left - titleW - 16), left + titleW + 14, TITLE_H / 2 + 2);
+ }
ctx.textBaseline = "alphabetic";
}
/** Draw the terminal screen of one pane, or its screensaver when `screen` is absent. */
-export function drawTerminalScreen(
- ctx: CanvasRenderingContext2D,
- agent: { name: string; dot: ScreenDot },
- screen: PaneScreen | undefined,
-): void {
+export function drawTerminalScreen(ctx: CanvasRenderingContext2D, face: MonitorFace, screen: PaneScreen | undefined): void {
if (!screen) {
- drawScreensaver(ctx, agent);
+ drawScreensaver(ctx, face);
return;
}
- ctx.fillStyle = "#0b0e14";
+ const { palette } = face;
+ ctx.fillStyle = palette.ground;
ctx.fillRect(0, 0, TERMINAL_W, TERMINAL_H);
- titleBar(ctx, agent.name, agent.dot);
+ titleBar(ctx, face);
const layout = terminalLayout(screen.cols);
const { rows, first } = visibleRows(screen.lines, layout.fit, screen.cursor);
- ctx.font = `${layout.font}px ${MONO}`;
+ const tones = rowTones(rows);
+ ctx.font = `${TERMINAL_FONT_WEIGHT} ${layout.font}px ${TERMINAL_FONT_STACK}`;
ctx.textBaseline = "alphabetic";
- ctx.fillStyle = "#d1d5db";
+ ctx.textAlign = "left";
const top = TITLE_H + PAD / 2;
const charW = layout.font * CHAR_RATIO;
rows.forEach((row, i) => {
- if (row) ctx.fillText(truncateRow(row, layout.cols), PAD, top + (i + 1) * layout.lineH - layout.lineH * 0.22);
+ if (!row) return;
+ ctx.fillStyle = tones[i] === "rule" ? palette.rule : tones[i] === "status" ? palette.inkMuted : palette.text;
+ ctx.fillText(truncateRow(row, layout.cols), PAD, top + (i + 1) * layout.lineH - layout.lineH * 0.24);
});
if (screen.cursor) {
const [row, col] = screen.cursor;
const at = row - first;
if (at >= 0 && at < rows.length && col < layout.cols) {
- ctx.fillStyle = "rgba(229, 231, 235, 0.85)";
- ctx.fillRect(PAD + col * charW, top + at * layout.lineH + 1, Math.max(2, charW), layout.lineH - 2);
+ ctx.fillStyle = palette.cursor;
+ ctx.fillRect(PAD + col * charW, top + at * layout.lineH + 2, Math.max(2, charW), layout.lineH - 4);
}
}
}
-/** A dim face for a monitor whose agent is away or whose screen has not arrived. */
-export function drawScreensaver(ctx: CanvasRenderingContext2D, agent: { name: string; dot: ScreenDot }): void {
- ctx.fillStyle = "#07090d";
+/** A monitor whose agent is away, or whose screen has not arrived: the pane's header over a quiet ground. */
+export function drawScreensaver(ctx: CanvasRenderingContext2D, face: MonitorFace): void {
+ const { palette } = face;
+ ctx.fillStyle = palette.ground;
ctx.fillRect(0, 0, TERMINAL_W, TERMINAL_H);
- ctx.fillStyle = "rgba(148, 163, 184, 0.35)";
- ctx.font = `600 22px ${SANS}`;
+ titleBar(ctx, face);
+ ctx.fillStyle = face.dot === "error" ? palette.dot.error : palette.inkFaint;
+ ctx.font = `${TERMINAL_FONT_WEIGHT} 44px ${TERMINAL_FONT_STACK}`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
- ctx.fillText(truncateRow(agent.name, 40), TERMINAL_W / 2, TERMINAL_H / 2 - 18);
- ctx.font = `28px ${MONO}`;
- ctx.fillStyle = agent.dot === "error" ? "rgba(248, 113, 113, 0.45)" : "rgba(148, 163, 184, 0.3)";
- ctx.fillText(">_", TERMINAL_W / 2, TERMINAL_H / 2 + 22);
+ ctx.fillText(">_", TERMINAL_W / 2, (TERMINAL_H + TITLE_H) / 2);
ctx.textAlign = "start";
ctx.textBaseline = "alphabetic";
}