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.
This commit is contained in:
4 files changed
+79
-9
No files matched your search
@@ -16,6 +16,7 @@ import { FitAddon } from "@xterm/addon-fit";
|
|||||||
import "@xterm/xterm/css/xterm.css";
|
import "@xterm/xterm/css/xterm.css";
|
||||||
|
|
||||||
import { setupTerminalURL } from "./harness";
|
import { setupTerminalURL } from "./harness";
|
||||||
|
import { followTerminalTheme, terminalTheme } from "@/lib/terminalTheme";
|
||||||
|
|
||||||
const props = defineProps<{ profile: string }>();
|
const props = defineProps<{ profile: string }>();
|
||||||
// The parent resets its open flag when the session ends, so reopening starts
|
// 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 socket: WebSocket | null = null;
|
||||||
let fit: FitAddon | null = null;
|
let fit: FitAddon | null = null;
|
||||||
let observer: ResizeObserver | null = null;
|
let observer: ResizeObserver | null = null;
|
||||||
|
let stopTheme: (() => void) | null = null;
|
||||||
|
|
||||||
function fitLocal(): void {
|
function fitLocal(): void {
|
||||||
try {
|
try {
|
||||||
@@ -48,12 +50,7 @@ onMounted(() => {
|
|||||||
cursorBlink: true,
|
cursorBlink: true,
|
||||||
fontFamily: "'IBM Plex Mono', ui-monospace, monospace",
|
fontFamily: "'IBM Plex Mono', ui-monospace, monospace",
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
theme: {
|
theme: terminalTheme(),
|
||||||
background: "#0b0f14",
|
|
||||||
foreground: "#e6edf3",
|
|
||||||
cursor: "#e6edf3",
|
|
||||||
selectionBackground: "#264f78",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
fit = new FitAddon();
|
fit = new FitAddon();
|
||||||
term.loadAddon(fit);
|
term.loadAddon(fit);
|
||||||
@@ -92,9 +89,15 @@ onMounted(() => {
|
|||||||
|
|
||||||
observer = new ResizeObserver(fitLocal);
|
observer = new ResizeObserver(fitLocal);
|
||||||
observer.observe(mount);
|
observer.observe(mount);
|
||||||
|
|
||||||
|
stopTheme = followTerminalTheme((t) => {
|
||||||
|
if (term) term.options.theme = t;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
stopTheme?.();
|
||||||
|
stopTheme = null;
|
||||||
observer?.disconnect();
|
observer?.disconnect();
|
||||||
observer = null;
|
observer = null;
|
||||||
socket?.close();
|
socket?.close();
|
||||||
@@ -118,7 +121,7 @@ onBeforeUnmount(() => {
|
|||||||
</p>
|
</p>
|
||||||
<div
|
<div
|
||||||
ref="host"
|
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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
@@ -94,6 +94,8 @@
|
|||||||
--color-input: var(--input);
|
--color-input: var(--input);
|
||||||
--color-ring: var(--ring);
|
--color-ring: var(--ring);
|
||||||
--color-hairline: var(--hairline);
|
--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: var(--card);
|
||||||
--color-sidebar-foreground: var(--card-foreground);
|
--color-sidebar-foreground: var(--card-foreground);
|
||||||
@@ -191,6 +193,12 @@
|
|||||||
--workspace: #16171a;
|
--workspace: #16171a;
|
||||||
--hairline: #2a2c30;
|
--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-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
|
||||||
--shadow-md: 0 8px 28px rgba(0, 0, 0, 0.4);
|
--shadow-md: 0 8px 28px rgba(0, 0, 0, 0.4);
|
||||||
--shadow-workspace: none;
|
--shadow-workspace: none;
|
||||||
@@ -255,6 +263,12 @@
|
|||||||
--workspace: #f5f4f1;
|
--workspace: #f5f4f1;
|
||||||
--hairline: #d6d3cc;
|
--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-sm: 0 1px 2px rgba(31, 31, 29, 0.06);
|
||||||
--shadow-md: 0 8px 28px rgba(31, 31, 29, 0.1);
|
--shadow-md: 0 8px 28px rgba(31, 31, 29, 0.1);
|
||||||
--shadow-workspace: none;
|
--shadow-workspace: none;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { onBeforeUnmount, onMounted, ref } from "vue";
|
|||||||
import { Terminal } from "@xterm/xterm";
|
import { Terminal } from "@xterm/xterm";
|
||||||
import { FitAddon } from "@xterm/addon-fit";
|
import { FitAddon } from "@xterm/addon-fit";
|
||||||
import "@xterm/xterm/css/xterm.css";
|
import "@xterm/xterm/css/xterm.css";
|
||||||
|
import { followTerminalTheme, terminalTheme } from "@/lib/terminalTheme";
|
||||||
|
|
||||||
const props = defineProps<{ taskId: string; attempt: number }>();
|
const props = defineProps<{ taskId: string; attempt: number }>();
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ let term: Terminal | null = null;
|
|||||||
let socket: WebSocket | null = null;
|
let socket: WebSocket | null = null;
|
||||||
let fit: FitAddon | null = null;
|
let fit: FitAddon | null = null;
|
||||||
let observer: ResizeObserver | null = null;
|
let observer: ResizeObserver | null = null;
|
||||||
|
let stopTheme: (() => void) | null = null;
|
||||||
|
|
||||||
function fitLocal(): void {
|
function fitLocal(): void {
|
||||||
try {
|
try {
|
||||||
@@ -40,7 +42,7 @@ onMounted(() => {
|
|||||||
cursorBlink: false,
|
cursorBlink: false,
|
||||||
fontFamily: "'IBM Plex Mono', ui-monospace, monospace",
|
fontFamily: "'IBM Plex Mono', ui-monospace, monospace",
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
theme: { background: "#0b0f14", foreground: "#e6edf3" },
|
theme: terminalTheme(),
|
||||||
});
|
});
|
||||||
fit = new FitAddon();
|
fit = new FitAddon();
|
||||||
term.loadAddon(fit);
|
term.loadAddon(fit);
|
||||||
@@ -75,9 +77,15 @@ onMounted(() => {
|
|||||||
|
|
||||||
observer = new ResizeObserver(fitLocal);
|
observer = new ResizeObserver(fitLocal);
|
||||||
observer.observe(mount);
|
observer.observe(mount);
|
||||||
|
|
||||||
|
stopTheme = followTerminalTheme((t) => {
|
||||||
|
if (term) term.options.theme = t;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
stopTheme?.();
|
||||||
|
stopTheme = null;
|
||||||
observer?.disconnect();
|
observer?.disconnect();
|
||||||
observer = null;
|
observer = null;
|
||||||
socket?.close();
|
socket?.close();
|
||||||
@@ -101,7 +109,7 @@ onBeforeUnmount(() => {
|
|||||||
</p>
|
</p>
|
||||||
<div
|
<div
|
||||||
ref="host"
|
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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
Reference in new issue
Block a user