From cb3372ac76d8d302cbae65ed7b7588a3ac5ec272 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 7 Nov 2026 01:13:41 +1100 Subject: [PATCH] fix(ui): terminal palette is theme tokens, switches live (#1739) --terminal-bg/fg/cursor/selection are defined per theme in style.css (dark keeps the deep well, light gets a paper inset) and exposed as bg-terminal. Both xterm surfaces (SetupTerminal, SandboxView) read them via lib/terminalTheme and re-apply on every data-theme flip, so the theme switch is live; the raw #0b0f14/#e6edf3/#264f78 hex is gone. --- ui/src/harness/SetupTerminal.vue | 17 +++++++----- ui/src/lib/terminalTheme.ts | 45 ++++++++++++++++++++++++++++++++ ui/src/style.css | 14 ++++++++++ ui/src/tasks/SandboxView.vue | 12 +++++++-- 4 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 ui/src/lib/terminalTheme.ts diff --git a/ui/src/harness/SetupTerminal.vue b/ui/src/harness/SetupTerminal.vue index 06ee2e3bd..a7c00d9df 100644 --- a/ui/src/harness/SetupTerminal.vue +++ b/ui/src/harness/SetupTerminal.vue @@ -16,6 +16,7 @@ import { FitAddon } from "@xterm/addon-fit"; import "@xterm/xterm/css/xterm.css"; import { setupTerminalURL } from "./harness"; +import { followTerminalTheme, terminalTheme } from "@/lib/terminalTheme"; const props = defineProps<{ profile: string }>(); // The parent resets its open flag when the session ends, so reopening starts @@ -29,6 +30,7 @@ let term: Terminal | null = null; let socket: WebSocket | null = null; let fit: FitAddon | null = null; let observer: ResizeObserver | null = null; +let stopTheme: (() => void) | null = null; function fitLocal(): void { try { @@ -48,12 +50,7 @@ onMounted(() => { cursorBlink: true, fontFamily: "'IBM Plex Mono', ui-monospace, monospace", fontSize: 13, - theme: { - background: "#0b0f14", - foreground: "#e6edf3", - cursor: "#e6edf3", - selectionBackground: "#264f78", - }, + theme: terminalTheme(), }); fit = new FitAddon(); term.loadAddon(fit); @@ -92,9 +89,15 @@ onMounted(() => { observer = new ResizeObserver(fitLocal); observer.observe(mount); + + stopTheme = followTerminalTheme((t) => { + if (term) term.options.theme = t; + }); }); onBeforeUnmount(() => { + stopTheme?.(); + stopTheme = null; observer?.disconnect(); observer = null; socket?.close(); @@ -118,7 +121,7 @@ onBeforeUnmount(() => {

diff --git a/ui/src/lib/terminalTheme.ts b/ui/src/lib/terminalTheme.ts new file mode 100644 index 000000000..b5f223c23 --- /dev/null +++ b/ui/src/lib/terminalTheme.ts @@ -0,0 +1,45 @@ +/** + * The xterm palette, read from the --terminal-* theme tokens so a terminal + * follows the dashboard theme instead of hard-coded hex. DOM-bound, unlike + * the pure helpers in format.ts. + */ + +/** Structural subset of xterm's ITheme, so this module need not import @xterm/xterm. */ +export interface TerminalTheme { + background: string; + foreground: string; + cursor: string; + selectionBackground: string; +} + +function readToken(name: string): string { + return getComputedStyle(document.documentElement).getPropertyValue(name).trim(); +} + +/** The current terminal palette from the theme tokens in style.css. */ +export function terminalTheme(): TerminalTheme { + return { + background: readToken("--terminal-bg"), + foreground: readToken("--terminal-fg"), + cursor: readToken("--terminal-cursor"), + selectionBackground: readToken("--terminal-selection"), + }; +} + +/** + * Applies the terminal theme now and again on every theme switch. The + * appearance store rewrites data-theme on — including OS-level + * changes while the preference is "system" — so watching that one attribute + * covers live switching. Returns the stop function. + */ +export function followTerminalTheme(apply: (theme: TerminalTheme) => void): () => void { + apply(terminalTheme()); + const observer = new MutationObserver((mutations) => { + if (mutations.some((m) => m.attributeName === "data-theme")) apply(terminalTheme()); + }); + observer.observe(document.documentElement, { + attributes: true, + attributeFilter: ["data-theme"], + }); + return () => observer.disconnect(); +} diff --git a/ui/src/style.css b/ui/src/style.css index e99924f7a..e5e01cfcc 100644 --- a/ui/src/style.css +++ b/ui/src/style.css @@ -94,6 +94,8 @@ --color-input: var(--input); --color-ring: var(--ring); --color-hairline: var(--hairline); + /* Terminal (xterm) host box; the palette itself is read via getComputedStyle. */ + --color-terminal: var(--terminal-bg); --color-sidebar: var(--card); --color-sidebar-foreground: var(--card-foreground); @@ -191,6 +193,12 @@ --workspace: #16171a; --hairline: #2a2c30; + /* Terminal well: darker than the card so the stream reads as a well. */ + --terminal-bg: #0b0f14; + --terminal-fg: var(--foreground); + --terminal-cursor: var(--foreground); + --terminal-selection: #264f78; + --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.4); --shadow-workspace: none; @@ -255,6 +263,12 @@ --workspace: #f5f4f1; --hairline: #d6d3cc; + /* Paper inset: the light-theme terminal is light, not a dark well. */ + --terminal-bg: #f5f4f1; + --terminal-fg: var(--foreground); + --terminal-cursor: var(--foreground); + --terminal-selection: #c9d8e8; + --shadow-sm: 0 1px 2px rgba(31, 31, 29, 0.06); --shadow-md: 0 8px 28px rgba(31, 31, 29, 0.1); --shadow-workspace: none; diff --git a/ui/src/tasks/SandboxView.vue b/ui/src/tasks/SandboxView.vue index 1f0593a0a..8273327c4 100644 --- a/ui/src/tasks/SandboxView.vue +++ b/ui/src/tasks/SandboxView.vue @@ -10,6 +10,7 @@ import { onBeforeUnmount, onMounted, ref } from "vue"; import { Terminal } from "@xterm/xterm"; import { FitAddon } from "@xterm/addon-fit"; import "@xterm/xterm/css/xterm.css"; +import { followTerminalTheme, terminalTheme } from "@/lib/terminalTheme"; const props = defineProps<{ taskId: string; attempt: number }>(); @@ -20,6 +21,7 @@ let term: Terminal | null = null; let socket: WebSocket | null = null; let fit: FitAddon | null = null; let observer: ResizeObserver | null = null; +let stopTheme: (() => void) | null = null; function fitLocal(): void { try { @@ -40,7 +42,7 @@ onMounted(() => { cursorBlink: false, fontFamily: "'IBM Plex Mono', ui-monospace, monospace", fontSize: 13, - theme: { background: "#0b0f14", foreground: "#e6edf3" }, + theme: terminalTheme(), }); fit = new FitAddon(); term.loadAddon(fit); @@ -75,9 +77,15 @@ onMounted(() => { observer = new ResizeObserver(fitLocal); observer.observe(mount); + + stopTheme = followTerminalTheme((t) => { + if (term) term.options.theme = t; + }); }); onBeforeUnmount(() => { + stopTheme?.(); + stopTheme = null; observer?.disconnect(); observer = null; socket?.close(); @@ -101,7 +109,7 @@ onBeforeUnmount(() => {