fix(ui): terminal palette is theme tokens, switches live (#1739)
Quality / check (push) Canceled after 3m23s
deploy / gate (push) Successful in 4m51s
deploy / archied-image (push) Successful in 3m22s
deploy / agent-image (push) Successful in 11s
deploy / dist-zip (push) Skipped

--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.
This commit is contained in:
sam committed 2026-11-07 01:13:41 +11:00
1 parent 48e605a545
commit cb3372ac76
4 files changed
+79 -9

No files matched your search

+10 -7
View File
@@ -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(() => {
</p>
<div
ref="host"
class="min-h-0 flex-1 overflow-hidden rounded-md border border-border bg-[#0b0f14] p-2"
class="min-h-0 flex-1 overflow-hidden rounded-md border border-border bg-terminal p-2"
/>
</div>
</template>
+45
View File
@@ -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 <html> — 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();
}
+14
View File
@@ -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;
+10 -2
View File
@@ -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(() => {
</p>
<div
ref="host"
class="min-h-0 flex-1 overflow-hidden rounded-md border border-border bg-[#0b0f14] p-2"
class="min-h-0 flex-1 overflow-hidden rounded-md border border-border bg-terminal p-2"
/>
</div>
</template>