Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(terminal): colour themes, cursor + spacing settings, one appearance source

enes259425ddb9b9
diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx
index 6562c30f7..165f53bd0 100644
--- a/src/renderer/App.tsx
+++ b/src/renderer/App.tsx
@@ -7,6 +7,7 @@ import { localSession } from './session/localSession'
import { useSettings } from './state/settings'
import { useViewMode } from './state/viewMode'
import { setWebglEnabled } from './terminal/webgl-budget'
+import { resolveTerminalTheme } from './terminal/themes'
import { resolveGpuRendering } from '../shared/webgl'
import { isMacPlatform } from '../shared/platform-utils'
@@ -21,6 +22,17 @@ export default function App() {
setWebglEnabled(resolveGpuRendering(gpu, isMacPlatform()))
}, [gpu])
+ // Publish the active terminal theme's background as a CSS variable. xterm paints its own
+ // background, but the chrome AROUND it does not: the canvas node's body shows through the few px
+ // its xterm host is inset by (and through a co-attach letterbox), and the kanban card modal
+ // frames its terminal in an 8px pad. Without this both keep the app's colour and every
+ // non-default theme renders inside a mismatched frame.
+ const terminalTheme = useSettings((s) => s.settings.terminalTheme)
+ useEffect(() => {
+ const { background } = resolveTerminalTheme(terminalTheme).theme
+ if (background) document.documentElement.style.setProperty('--term-bg', background)
+ }, [terminalTheme])
+
// Keep the view-mode store's default in sync with the Settings choice, so projects the user
// hasn't explicitly toggled follow it (and flip live when the setting changes).
const defaultView = useSettings((s) => s.settings.defaultProjectView)
diff --git a/src/renderer/components/kanban/ModalTerminal.tsx b/src/renderer/components/kanban/ModalTerminal.tsx
index 26f23f79f..1dc1a0f75 100644
--- a/src/renderer/components/kanban/ModalTerminal.tsx
+++ b/src/renderer/components/kanban/ModalTerminal.tsx
@@ -18,7 +18,8 @@ import {
stripTrailingNewline,
terminalKeyAction,
toXtermText,
- xtermScrollback,
+ applyLiveOptions,
+ xtermOptionsFromSettings,
SHIFT_ENTER_SEQ,
CO_ATTACH_MOUSE_SEQ
} from '../../terminal/terminal-config'
@@ -61,7 +62,24 @@ export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch }: Moda
const hostRef = useRef<HTMLDivElement>(null)
const termRef = useRef<Terminal | null>(null)
const searchAddonRef = useRef<SearchAddon | null>(null)
+ // The live pty session + its fit addon, reachable from OUTSIDE the lifecycle effect's closure —
+ // the appearance effect below has to re-fit and re-REPORT this viewer's grid, and under co-attach
+ // a report that never happens leaves the shared pty clamped to the pre-change size.
+ const sessionIdRef = useRef<string | null>(null)
+ const fitRef = useRef<FitAddon | null>(null)
+ const transportRef = useRef<LocalTransport | null>(null)
const agentSessionId = useAgentStatus((s) => s.byId[nodeId]?.sessionId)
+ // Scoped selectors (not the whole settings object), same discipline as TerminalNode: a modal
+ // holding a live terminal must not re-render on every unrelated settings edit.
+ const fontSize = useSettings((s) => s.settings.fontSize)
+ const fontFamily = useSettings((s) => s.settings.fontFamily)
+ const cursorBlink = useSettings((s) => s.settings.cursorBlink)
+ const cursorStyle = useSettings((s) => s.settings.cursorStyle)
+ const cursorInactiveStyle = useSettings((s) => s.settings.cursorInactiveStyle)
+ const terminalLineHeightSetting = useSettings((s) => s.settings.terminalLineHeight)
+ const terminalLetterSpacingSetting = useSettings((s) => s.settings.terminalLetterSpacing)
+ const terminalTheme = useSettings((s) => s.settings.terminalTheme)
+ const tmuxScrollback = useSettings((s) => s.settings.tmuxScrollback)
const [dropping, setDropping] = useState(false)
const [uploading, setUploading] = useState(false)
@@ -108,21 +126,18 @@ export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch }: Moda
const viewerId = `modal-${nodeId}-${Math.random().toString(36).slice(2, 8)}`
const transport = new LocalTransport(api, viewerId)
const s = useSettings.getState().settings
- const term = new Terminal({
- fontFamily: s.fontFamily,
- fontSize: s.fontSize,
- cursorBlink: s.cursorBlink,
- theme: { background: '#161618', foreground: '#e6e6e6' },
- allowProposedApi: true,
- scrollback: xtermScrollback(s.tmuxScrollback),
- macOptionClickForcesSelection: true
- })
+ // Appearance comes from the SAME source as the canvas node's terminal — this modal is a second
+ // view of one session, and a card that renders it in different colours reads as a different
+ // terminal. (It used to hardcode its own background, which is exactly what happened.)
+ const term = new Terminal(xtermOptionsFromSettings(s))
const fit = new FitAddon()
term.loadAddon(fit)
const searchAddon = new SearchAddon()
term.loadAddon(searchAddon)
termRef.current = term
searchAddonRef.current = searchAddon
+ fitRef.current = fit
+ transportRef.current = transport
term.open(hostRef.current!)
fit.fit()
@@ -188,6 +203,7 @@ export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch }: Moda
return
}
sessionId = res.sessionId
+ sessionIdRef.current = res.sessionId
cleanups.push(transport.onData(res.sessionId, (d) => term.write(d)))
cleanups.push(
transport.onExit(res.sessionId, () =>
@@ -252,10 +268,51 @@ export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch }: Moda
// on until its last view goes.
if (sessionId) transport.kill(sessionId)
term.dispose()
+ sessionIdRef.current = null
+ fitRef.current = null
+ transportRef.current = null
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [nodeId])
+ // Live-apply the appearance settings, mirroring the canvas node's effect (see TerminalNode) —
+ // without this the modal kept whatever it was built with, so changing the font or the theme with
+ // a card open changed the canvas terminal and left its own second view of the SAME session
+ // looking different until the modal was reopened.
+ //
+ // Re-fitting here is not cosmetic: this viewer is a co-attach subscriber, and the pty runs at the
+ // smallest subscriber's grid. A viewer that changes its cell geometry without re-reporting keeps
+ // clamping the shared pty to its pre-change size — i.e. shrinks the canvas terminal too.
+ useEffect(() => {
+ const term = termRef.current
+ if (!term) return
+ const { metricsChanged } = applyLiveOptions(term, {
+ fontFamily,
+ fontSize,
+ cursorBlink,
+ cursorStyle,
+ cursorInactiveStyle,
+ terminalLineHeight: terminalLineHeightSetting,
+ terminalLetterSpacing: terminalLetterSpacingSetting,
+ terminalTheme,
+ tmuxScrollback
+ })
+ if (!metricsChanged) return
+ fitRef.current?.fit()
+ const sid = sessionIdRef.current
+ if (sid) transportRef.current?.resize(sid, term.cols, term.rows)
+ }, [
+ fontSize,
+ fontFamily,
+ cursorBlink,
+ cursorStyle,
+ cursorInactiveStyle,
+ terminalLineHeightSetting,
+ terminalLetterSpacingSetting,
+ terminalTheme,
+ tmuxScrollback
+ ])
+
// File drop → paste the path(s) into the co-attached session, just like the canvas node.
const onDragOver = (e: React.DragEvent) => {
if (!Array.from(e.dataTransfer.types).includes('Files')) return
diff --git a/src/renderer/components/settings/TerminalPreview.tsx b/src/renderer/components/settings/TerminalPreview.tsx
new file mode 100644
index 000000000..fc4f0a176
--- /dev/null
+++ b/src/renderer/components/settings/TerminalPreview.tsx
@@ -0,0 +1,108 @@
+import { useEffect, useRef } from 'react'
+import { Terminal } from '@xterm/xterm'
+import { useSettings } from '../../state/settings'
+import { applyLiveOptions, xtermOptionsFromSettings } from '../../terminal/terminal-config'
+
+/** Fixed grid — the preview is a sample, not a fitted terminal, so there is no FitAddon and no
+ * ResizeObserver to keep in sync. Wide enough for the sample lines below without wrapping. */
+const PREVIEW_COLS = 46
+const PREVIEW_ROWS = 9
+
+/**
+ * The sample screen. Deliberately exercises what the settings on this page change: all sixteen
+ * ANSI colours (as a swatch row — a theme's palette is most of what a theme IS), bold/dim/italic/
+ * underline attributes, box-drawing characters (agent CLIs frame their output with these, and they
+ * are what a bad letter-spacing tears apart) and a resting cursor.
+ */
+const SAMPLE = [
+ '\x1b[32m➜\x1b[0m \x1b[36mnodeterm\x1b[0m \x1b[33mgit:(\x1b[31mmain\x1b[33m)\x1b[0m npm test',
+ '\x1b[90m┌────────────────────────────────┐\x1b[0m',
+ '\x1b[90m│\x1b[0m \x1b[32m✓\x1b[0m terminal-config \x1b[90m117 passed\x1b[0m \x1b[90m│\x1b[0m',
+ '\x1b[90m│\x1b[0m \x1b[31m✗\x1b[0m workspace-files \x1b[90m 1 failed\x1b[0m \x1b[90m│\x1b[0m',
+ '\x1b[90m└────────────────────────────────┘\x1b[0m',
+ '\x1b[1mbold\x1b[0m \x1b[2mdim\x1b[0m \x1b[3mitalic\x1b[0m \x1b[4munderline\x1b[0m \x1b[7mreverse\x1b[0m',
+ // Eight normal backgrounds (40-47) then eight bright ones (100-107).
+ [40, 41, 42, 43, 44, 45, 46, 47, 100, 101, 102, 103, 104, 105, 106, 107]
+ .map((c) => `\x1b[${c}m `)
+ .join('') + '\x1b[0m',
+ '\x1b[32m➜\x1b[0m '
+].join('\r\n')
+
+/**
+ * A live, non-interactive xterm rendering a sample screen with the user's current appearance
+ * settings — so picking a theme or nudging the line height is a look, not a guess-and-check trip
+ * back to the canvas.
+ *
+ * Two things this must NOT do:
+ * - **Register with the WebGL budget coordinator.** Contexts are a hard-capped shared resource
+ * (`terminal/webgl-budget.ts`); a preview that took one would evict a real terminal every time
+ * the Settings panel opened. It stays on the DOM renderer, which is what a static 46×9 sample
+ * wants anyway.
+ * - **Accept input.** `disableStdin` keeps it a picture. It can still take FOCUS on click, which is
+ * the only way to see the active (rather than the inactive) cursor style.
+ */
+export function TerminalPreview(): React.JSX.Element {
+ const hostRef = useRef<HTMLDivElement>(null)
+ const termRef = useRef<Terminal | null>(null)
+
+ const fontSize = useSettings((s) => s.settings.fontSize)
+ const fontFamily = useSettings((s) => s.settings.fontFamily)
+ const cursorBlink = useSettings((s) => s.settings.cursorBlink)
+ const cursorStyle = useSettings((s) => s.settings.cursorStyle)
+ const cursorInactiveStyle = useSettings((s) => s.settings.cursorInactiveStyle)
+ const terminalLineHeight = useSettings((s) => s.settings.terminalLineHeight)
+ const terminalLetterSpacing = useSettings((s) => s.settings.terminalLetterSpacing)
+ const terminalTheme = useSettings((s) => s.settings.terminalTheme)
+ const tmuxScrollback = useSettings((s) => s.settings.tmuxScrollback)
+
+ useEffect(() => {
+ const s = useSettings.getState().settings
+ const term = new Terminal({
+ ...xtermOptionsFromSettings(s),
+ cols: PREVIEW_COLS,
+ rows: PREVIEW_ROWS,
+ disableStdin: true
+ })
+ termRef.current = term
+ term.open(hostRef.current!)
+ term.write(SAMPLE)
+ return () => {
+ termRef.current = null
+ term.dispose()
+ }
+ }, [])
+
+ // Same live-apply path as the real terminals. No re-fit: the grid is fixed, so a metrics change
+ // just makes the sample render bigger or smaller — which is the point of previewing it.
+ useEffect(() => {
+ const term = termRef.current
+ if (!term) return
+ applyLiveOptions(term, {
+ fontFamily,
+ fontSize,
+ cursorBlink,
+ cursorStyle,
+ cursorInactiveStyle,
+ terminalLineHeight,
+ terminalLetterSpacing,
+ terminalTheme,
+ tmuxScrollback
+ })
+ }, [
+ fontSize,
+ fontFamily,
+ cursorBlink,
+ cursorStyle,
+ cursorInactiveStyle,
+ terminalLineHeight,
+ terminalLetterSpacing,
+ terminalTheme,
+ tmuxScrollback
+ ])
+
+ return (
+ <div className="settings-term-preview">
+ <div ref={hostRef} />
+ </div>
+ )
+}
diff --git a/src/renderer/components/settings/sections/TerminalSection.tsx b/src/renderer/components/settings/sections/TerminalSection.tsx
index 73d267e12..f48a66afd 100644
--- a/src/renderer/components/settings/sections/TerminalSection.tsx
+++ b/src/renderer/components/settings/sections/TerminalSection.tsx
@@ -2,16 +2,68 @@ import { useSettings } from '../../../state/settings'
import { SettingsSection } from '../SettingsSection'
import { SearchableRow } from '../SearchableRow'
import { FieldRow } from '../FieldRow'
+import { TerminalPreview } from '../TerminalPreview'
import { Input } from '@renderer/ui/Input'
import { Switch } from '@renderer/ui/Switch'
+import { Select } from '@renderer/ui/Select'
import { NumberField } from '@renderer/ui/NumberField'
+import { SegmentedPill } from '@renderer/ui/SegmentedPill'
+import { TERMINAL_THEMES, resolveTerminalTheme } from '@renderer/terminal/themes'
+import {
+ TERMINAL_LETTER_SPACING_MAX,
+ TERMINAL_LETTER_SPACING_MIN,
+ TERMINAL_LINE_HEIGHT_MAX,
+ TERMINAL_LINE_HEIGHT_MIN
+} from '@renderer/terminal/terminal-config'
import { resolveGpuRendering } from '@shared/webgl'
import { isMacPlatform } from '@shared/platform-utils'
+import type { TerminalCursorInactiveStyle, TerminalCursorStyle } from '@shared/types'
+// One entry per row. The keywords matter as much as the titles: settings search matches on them,
+// and an appearance setting is far more often looked for by symptom ("colors", "scheme",
+// "spacing") than by whatever we chose to call it.
const ROWS = {
- fontSize: { title: 'Font size', keywords: ['font', 'size', 'text'] },
- fontFamily: { title: 'Font family', keywords: ['font', 'family', 'typeface', 'monospace'] },
+ fontSize: { title: 'Font size', keywords: ['font', 'size', 'text', 'zoom'] },
+ fontFamily: {
+ title: 'Font family',
+ keywords: ['font', 'family', 'typeface', 'monospace', 'mono']
+ },
+ theme: {
+ title: 'Colour theme',
+ keywords: [
+ 'theme',
+ 'color',
+ 'colour',
+ 'scheme',
+ 'palette',
+ 'ansi',
+ 'dracula',
+ 'nord',
+ 'gruvbox',
+ 'solarized',
+ 'tokyo',
+ 'catppuccin',
+ 'dark',
+ 'light'
+ ]
+ },
+ cursorStyle: {
+ title: 'Cursor style',
+ keywords: ['cursor', 'style', 'block', 'bar', 'beam', 'underline']
+ },
+ cursorInactive: {
+ title: 'Cursor when unfocused',
+ keywords: ['cursor', 'inactive', 'unfocused', 'blurred', 'outline']
+ },
cursorBlink: { title: 'Cursor blink', keywords: ['cursor', 'blink'] },
+ lineHeight: {
+ title: 'Line height',
+ keywords: ['line', 'height', 'leading', 'spacing', 'density']
+ },
+ letterSpacing: {
+ title: 'Letter spacing',
+ keywords: ['letter', 'spacing', 'tracking', 'character', 'width']
+ },
gpu: {
title: 'GPU terminal rendering',
keywords: ['gpu', 'webgl', 'renderer', 'flicker', 'performance', 'graphics', 'acceleration']
@@ -19,27 +71,76 @@ const ROWS = {
}
const ENTRIES = Object.values(ROWS)
+const CURSOR_STYLES: { value: TerminalCursorStyle; label: string }[] = [
+ { value: 'block', label: 'Block' },
+ { value: 'bar', label: 'Bar' },
+ { value: 'underline', label: 'Underline' }
+]
+
+const CURSOR_INACTIVE_STYLES: { value: TerminalCursorInactiveStyle; label: string }[] = [
+ { value: 'outline', label: 'Outline' },
+ { value: 'block', label: 'Block' },
+ { value: 'bar', label: 'Bar' },
+ { value: 'underline', label: 'Underline' },
+ { value: 'none', label: 'Hidden' }
+]
+
+/** A sub-heading inside the section. Terminal grew past the point where one flat list of rows
+ * reads as anything — the groups are what keep it scannable. */
+function GroupHeading({ children }: { children: React.ReactNode }): React.JSX.Element {
+ return (
+ <h4 className="text-[11px] font-semibold uppercase tracking-wide text-muted-2">{children}</h4>
+ )
+}
+
+/** The theme's background plus a few of its colours, so the picker is legible without reading
+ * every option's name. */
+function ThemeSwatch({ themeId }: { themeId: string }): React.JSX.Element {
+ const { theme } = resolveTerminalTheme(themeId)
+ return (
+ <span
+ className="inline-flex items-center gap-1 rounded border border-border px-1.5 py-1"
+ style={{ background: theme.background }}
+ aria-hidden="true"
+ >
+ {[theme.foreground, theme.red, theme.green, theme.yellow, theme.blue, theme.magenta].map(
+ (c, i) => (
+ <span key={i} className="size-2 rounded-full" style={{ background: c }} />
+ )
+ )}
+ </span>
+ )
+}
+
export function TerminalSection({ isActive }: { isActive: boolean }): React.JSX.Element {
const settings = useSettings((s) => s.settings)
const update = useSettings((s) => s.update)
+ const darkThemes = TERMINAL_THEMES.filter((t) => t.dark)
+ const lightThemes = TERMINAL_THEMES.filter((t) => !t.dark)
return (
<SettingsSection id="terminal" title="Terminal" isActive={isActive} searchEntries={ENTRIES}>
+ {/* The group headings ride on the FIRST row of each group rather than standing alone, so a
+ search that hides every row in a group takes its heading with it. */}
<SearchableRow {...ROWS.fontSize}>
- <FieldRow
- label="Font size"
- control={
- <NumberField
- value={settings.fontSize}
- min={8}
- max={28}
- onChange={(v) => update({ fontSize: v || 13 })}
- />
- }
- />
+ <div className="space-y-3">
+ <GroupHeading>Font</GroupHeading>
+ <FieldRow
+ label="Font size"
+ control={
+ <NumberField
+ value={settings.fontSize}
+ min={8}
+ max={28}
+ onChange={(v) => update({ fontSize: v || 13 })}
+ />
+ }
+ />
+ </div>
</SearchableRow>
<SearchableRow {...ROWS.fontFamily}>
<FieldRow
label="Font family"
+ description="A CSS font stack. Names that aren't installed are skipped, so keep a generic monospace last."
control={
<Input
className="w-64"
@@ -49,6 +150,84 @@ export function TerminalSection({ isActive }: { isActive: boolean }): React.JSX.
}
/>
</SearchableRow>
+
+ <SearchableRow {...ROWS.theme}>
+ <div className="space-y-3">
+ <GroupHeading>Colours</GroupHeading>
+ <FieldRow
+ label="Colour theme"
+ description="Applies to every terminal — on the canvas and in kanban cards."
+ control={
+ <span className="flex items-center gap-2">
+ <ThemeSwatch themeId={settings.terminalTheme} />
+ {/* Value goes through the resolver so a stored id we no longer ship shows the
+ default as selected, instead of leaving the picker apparently blank. */}
+ <Select
+ className="w-48"
+ value={resolveTerminalTheme(settings.terminalTheme).id}
+ onChange={(e) => update({ terminalTheme: e.target.value })}
+ aria-label="Colour theme"
+ >
+ <optgroup label="Dark">
+ {darkThemes.map((t) => (
+ <option key={t.id} value={t.id}>
+ {t.label}
+ </option>
+ ))}
+ </optgroup>
+ <optgroup label="Light">
+ {lightThemes.map((t) => (
+ <option key={t.id} value={t.id}>
+ {t.label}
+ </option>
+ ))}
+ </optgroup>
+ </Select>
+ </span>
+ }
+ />
+ <TerminalPreview />
+ </div>
+ </SearchableRow>
+
+ <SearchableRow {...ROWS.cursorStyle}>
+ <div className="space-y-3">
+ <GroupHeading>Cursor</GroupHeading>
+ <FieldRow
+ label="Cursor style"
+ control={
+ <SegmentedPill
+ value={settings.cursorStyle}
+ options={CURSOR_STYLES}
+ onChange={(v) => update({ cursorStyle: v })}
+ ariaLabel="Cursor style"
+ />
+ }
+ />
+ </div>
+ </SearchableRow>
+ <SearchableRow {...ROWS.cursorInactive}>
+ <FieldRow
+ label="Cursor when unfocused"
+ description="What the cursor looks like in a terminal that isn't taking your keystrokes — the quickest way to tell which of a canvas full of terminals is focused."
+ control={
+ <Select
+ className="w-36"
+ value={settings.cursorInactiveStyle}
+ onChange={(e) =>
+ update({ cursorInactiveStyle: e.target.value as TerminalCursorInactiveStyle })
+ }
+ aria-label="Cursor when unfocused"
+ >
+ {CURSOR_INACTIVE_STYLES.map((o) => (
+ <option key={o.value} value={o.value}>
+ {o.label}
+ </option>
+ ))}
+ </Select>
+ }
+ />
+ </SearchableRow>
<SearchableRow {...ROWS.cursorBlink}>
<FieldRow
label="Cursor blink"
@@ -61,23 +240,61 @@ export function TerminalSection({ isActive }: { isActive: boolean }): React.JSX.
}
/>
</SearchableRow>
- <SearchableRow {...ROWS.gpu}>
+
+ <SearchableRow {...ROWS.lineHeight}>
+ <div className="space-y-3">
+ <GroupHeading>Spacing</GroupHeading>
+ <FieldRow
+ label="Line height"
+ description="A multiple of the font size. Higher is airier but fits fewer rows."
+ control={
+ <NumberField
+ value={settings.terminalLineHeight}
+ min={TERMINAL_LINE_HEIGHT_MIN}
+ max={TERMINAL_LINE_HEIGHT_MAX}
+ step={0.05}
+ onChange={(v) => update({ terminalLineHeight: v || 1 })}
+ />
+ }
+ />
+ </div>
+ </SearchableRow>
+ <SearchableRow {...ROWS.letterSpacing}>
<FieldRow
- label="GPU terminal rendering"
- description={
- isMacPlatform()
- ? 'Off by default on macOS (WebGL terminals can flicker or composite black there). Turning it on is an explicit opt-in.'
- : 'Turn off if the window flickers. Terminals then use the DOM renderer (no WebGL).'
- }
+ label="Letter spacing"
+ description="Extra pixels between characters. Past a point the box-drawing characters agent CLIs frame their output with stop meeting."
control={
- <Switch
- checked={resolveGpuRendering(settings.terminalGpuRendering, isMacPlatform())}
- onChange={(v) => update({ terminalGpuRendering: v ? 'on' : 'off' })}
- ariaLabel="GPU terminal rendering"
+ <NumberField
+ value={settings.terminalLetterSpacing}
+ min={TERMINAL_LETTER_SPACING_MIN}
+ max={TERMINAL_LETTER_SPACING_MAX}
+ step={0.5}
+ onChange={(v) => update({ terminalLetterSpacing: v ?? 0 })}
/>
}
/>
</SearchableRow>
+
+ <SearchableRow {...ROWS.gpu}>
+ <div className="space-y-3">
+ <GroupHeading>Advanced</GroupHeading>
+ <FieldRow
+ label="GPU terminal rendering"
+ description={
+ isMacPlatform()
+ ? 'Off by default on macOS (WebGL terminals can flicker or composite black there). Turning it on is an explicit opt-in.'
+ : 'Turn off if the window flickers. Terminals then use the DOM renderer (no WebGL).'
+ }
+ control={
+ <Switch
+ checked={resolveGpuRendering(settings.terminalGpuRendering, isMacPlatform())}
+ onChange={(v) => update({ terminalGpuRendering: v ? 'on' : 'off' })}
+ ariaLabel="GPU terminal rendering"
+ />
+ }
+ />
+ </div>
+ </SearchableRow>
</SettingsSection>
)
}
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 1d13824ce..fb0e85d1f 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -48,9 +48,10 @@ import {
terminalKey,
terminalKeyAction,
toXtermText,
+ applyLiveOptions,
+ xtermOptionsFromSettings,
SHIFT_ENTER_SEQ,
CO_ATTACH_MOUSE_SEQ,
- xtermScrollback,
type SessionLife
} from '../terminal/terminal-config'
import { loseWebglContexts, registerWebglClient, type WebglClientHandle } from '../terminal/webgl-budget'
@@ -367,6 +368,11 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
const fontSize = useSettings((s) => s.settings.fontSize)
const fontFamily = useSettings((s) => s.settings.fontFamily)
const cursorBlink = useSettings((s) => s.settings.cursorBlink)
+ const cursorStyle = useSettings((s) => s.settings.cursorStyle)
+ const cursorInactiveStyle = useSettings((s) => s.settings.cursorInactiveStyle)
+ const terminalLineHeightSetting = useSettings((s) => s.settings.terminalLineHeight)
+ const terminalLetterSpacingSetting = useSettings((s) => s.settings.terminalLetterSpacing)
+ const terminalTheme = useSettings((s) => s.settings.terminalTheme)
const tmuxScrollback = useSettings((s) => s.settings.tmuxScrollback)
const claudeAccounts = useSettings((s) => s.settings.claudeAccounts)
// Header buttons the user chose to hide (Settings). A selector, so toggling one re-renders every
@@ -381,6 +387,9 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
// The live session's "measure my grid, render it, report it" routine (set by the lifecycle
// effect), so effects outside that closure (font/cursor changes) resize through the same path.
const applyFitRef = useRef<(() => void) | null>(null)
+ // The lifecycle effect's guaranteed full-viewport repaint, reachable from the appearance effect
+ // outside that closure (a theme swap must not be left to a refresh that can be swallowed).
+ const fullRepaintRef = useRef<(() => void) | null>(null)
// This project shows the KANBAN board (an opaque overlay over the canvas). While it does, this
// canvas terminal is not visible — but it is still a co-attach subscriber, and its (often
// zoomed-small) grid would clamp a CARD-MODAL viewer of the same session to a tiny size, pushing
@@ -605,22 +614,9 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
}
const s = useSettings.getState().settings
- const term =
- parked?.term ??
- new Terminal({
- fontFamily: s.fontFamily,
- fontSize: s.fontSize,
- cursorBlink: s.cursorBlink,
- theme: { background: '#1e1e1e', foreground: '#e6e6e6' },
- allowProposedApi: true,
- // NOT what the user scrolls in a tmux session — tmux's mouse is ON and the wheel scrolls
- // tmux's own history (see pty-manager's tmuxConf). This buffer backs the plain-shell
- // fallback (tmux unavailable) and the cold-snapshot replay. Capped: per node, many nodes.
- scrollback: xtermScrollback(s.tmuxScrollback),
- // Inside an app that requested mouse tracking (vim, htop) a plain drag goes to the app;
- // Option/Alt forces a selection instead (Shift does the same via xterm's own bypass).
- macOptionClickForcesSelection: true
- })
+ // Appearance comes from ONE place, shared with the kanban card modal's viewer of this same
+ // session (`ModalTerminal`) — see `xtermOptionsFromSettings`.
+ const term = parked?.term ?? new Terminal(xtermOptionsFromSettings(s))
const fit = parked ? parked.fit : new FitAddon()
const searchAddon = parked ? parked.search : new SearchAddon()
termRef.current = term
@@ -658,6 +654,9 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
}
})
}
+ // A palette swap repaints through exactly the path described above, so it is exposed to the
+ // same swallowed-refresh cases — and half a palette is the most visible way for one to fail.
+ fullRepaintRef.current = fullRepaint
// --- renderer-swap safety net ---------------------------------------------------------
// xterm treats a renderer swap as atomic; it is not. On macOS under GPU/canvas memory
// pressure, canvas allocation THROWS mid-swap (`throwIfFalsy(getContext('2d'))` in the
@@ -1499,6 +1498,7 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
fitRef.current = null
searchAddonRef.current = null
if (applyFitRef.current === applyFit) applyFitRef.current = null
+ if (fullRepaintRef.current === fullRepaint) fullRepaintRef.current = null
// Free the GPU context on unmount (park or teardown) either way, and unregister from the
// budget coordinator (which releases any held grant + cancels its timers). The park path must
// keep releasing it as it always has (contexts are capped ~16, and a parked terminal is
@@ -1551,23 +1551,46 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [data.respawnNonce])
- // Live-apply font/cursor/scrollback settings to the running terminal, so a Settings change
- // reaches the terminals already on the canvas instead of only the next fresh one.
+ // Live-apply the appearance settings to the running terminal, so a Settings change reaches the
+ // terminals already on the canvas instead of only the next fresh one.
+ //
+ // This must stay ONE effect that also runs on mount: a terminal ADOPTED from the park cache
+ // carries the options it was built with, and this pass is what brings it up to date. Splitting
+ // the new options into a second effect would work by accident today and break the moment one of
+ // them skips the mount run.
//
- // A new font size means new cell geometry, i.e. a different grid — route it through applyFit
- // (not a bare fit.fit()) so the pty is told the new size like any other resize, instead of
- // running at a grid nobody renders. Under co-attach applyFit is also what REPORTS our size, so
- // a font change must go through it or this client would silently keep clamping the shared pty
- // to its pre-change grid.
+ // A cell-geometry change (font, line height, letter spacing) means a different grid — route it
+ // through applyFit (not a bare fit.fit()) so the pty is told the new size like any other resize,
+ // instead of running at a grid nobody renders. Under co-attach applyFit is also what REPORTS our
+ // size, so it must go through it or this client would silently keep clamping the shared pty to
+ // its pre-change grid. A palette change costs no resize — just a repaint we force ourselves.
useEffect(() => {
const term = termRef.current
if (!term) return
- term.options.fontSize = fontSize
- term.options.fontFamily = fontFamily
- term.options.cursorBlink = cursorBlink
- term.options.scrollback = xtermScrollback(tmuxScrollback)
- applyFitRef.current?.()
- }, [fontSize, fontFamily, cursorBlink, tmuxScrollback])
+ const { metricsChanged, themeChanged } = applyLiveOptions(term, {
+ fontFamily,
+ fontSize,
+ cursorBlink,
+ cursorStyle,
+ cursorInactiveStyle,
+ terminalLineHeight: terminalLineHeightSetting,
+ terminalLetterSpacing: terminalLetterSpacingSetting,
+ terminalTheme,
+ tmuxScrollback
+ })
+ if (metricsChanged) applyFitRef.current?.()
+ if (themeChanged) fullRepaintRef.current?.()
+ }, [
+ fontSize,
+ fontFamily,
+ cursorBlink,
+ cursorStyle,
+ cursorInactiveStyle,
+ terminalLineHeightSetting,
+ terminalLetterSpacingSetting,
+ terminalTheme,
+ tmuxScrollback
+ ])
// Kanban board opened/closed: re-evaluate our size vote. Open → applyFit reports null (yield the
// grid to a card-modal viewer); close → it re-reports the real fit. On the first run boardOpen
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 1bde65c12..7b6b33757 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -1552,7 +1552,12 @@ body,
position: relative;
flex: 1;
min-height: 0;
- background: var(--bg);
+ /* The TERMINAL's background, not the app's: `.term-node__xterm` insets the xterm by a few px and
+ * a co-attach letterbox leaves unpainted space around it, so both bands show THIS rather than the
+ * theme — a mismatched frame around every terminal the moment a non-default theme is picked. Set
+ * from the active theme in App.tsx; the fallback is the app background, which is exactly what the
+ * default theme carries anyway. */
+ background: var(--term-bg, var(--bg));
}
/* Upload progress while dropped files scp to an SSH host (and a brief failure flash). */
@@ -7338,6 +7343,9 @@ body,
display: flex;
flex-direction: column;
padding: 8px; /* the terminal's inset — off the FitAddon-measured host (see .kanban-modal__term) */
+ /* Same reason as `.term-node__body`: this 8px inset would otherwise frame the terminal in the
+ * modal's own colour. The fallback is the modal surface, i.e. the pre-themes look. */
+ background: var(--term-bg, #161618);
}
.kanban-modal__action[aria-pressed='true'] {
background: var(--accent);
@@ -9137,3 +9145,26 @@ body,
justify-content: center;
gap: 10px;
}
+
+/* ---- Settings → Terminal: the live appearance preview ---- */
+/* A real (non-interactive) xterm at a fixed 46x9 grid. It sizes itself from the font metrics, so
+ the frame just wraps it — no fit addon is involved and nothing here may set a width the terminal
+ would then be measured against. */
+.settings-term-preview {
+ display: inline-block;
+ padding: 8px;
+ border: 1px solid var(--border);
+ border-radius: 8px;
+ background: var(--term-bg, var(--bg));
+ overflow: hidden;
+}
+
+/* The preview never scrolls (one screen, no scrollback in view) — hide the reserved bar the same
+ way the canvas terminals do, so it can't draw a dead band down the right-hand side. */
+.settings-term-preview .xterm-viewport {
+ scrollbar-width: none;
+}
+.settings-term-preview .xterm-viewport::-webkit-scrollbar {
+ width: 0;
+ height: 0;
+}
diff --git a/src/renderer/terminal/terminal-config.test.ts b/src/renderer/terminal/terminal-config.test.ts
index 59da4ac82..10a95ef35 100644
--- a/src/renderer/terminal/terminal-config.test.ts
+++ b/src/renderer/terminal/terminal-config.test.ts
@@ -22,12 +22,23 @@ import {
terminalKeyAction,
toXtermText,
xtermScrollback,
+ applyLiveOptions,
+ terminalLetterSpacing,
+ terminalLineHeight,
+ xtermOptionsFromSettings,
RESYNC_NOTICE,
SHIFT_ENTER_SEQ,
+ TERMINAL_LETTER_SPACING_MAX,
+ TERMINAL_LETTER_SPACING_MIN,
+ TERMINAL_LINE_HEIGHT_MAX,
+ TERMINAL_LINE_HEIGHT_MIN,
XTERM_SCROLLBACK_MAX,
XTERM_SCROLLBACK_MIN,
- type CopyShortcutEvent
+ type CopyShortcutEvent,
+ type LiveOptionTarget,
+ type XtermVisualSettings
} from './terminal-config'
+import { resolveTerminalTheme } from './themes'
import type { ClientId } from '@shared/presence'
const ev = (p: Partial<CopyShortcutEvent>): CopyShortcutEvent => ({
@@ -636,3 +647,169 @@ describe('repaintResync', () => {
expect(term.ops).toContain('write:TWO')
})
})
+
+const visual = (p: Partial<XtermVisualSettings> = {}): XtermVisualSettings => ({
+ fontFamily: 'Menlo',
+ fontSize: 13,
+ cursorBlink: true,
+ cursorStyle: 'block',
+ cursorInactiveStyle: 'outline',
+ terminalLineHeight: 1,
+ terminalLetterSpacing: 0,
+ terminalTheme: 'nodeterm-dark',
+ tmuxScrollback: 50000,
+ ...p
+})
+
+describe('terminalLineHeight / terminalLetterSpacing (clamps)', () => {
+ it('passes through in-range values', () => {
+ expect(terminalLineHeight(1.4)).toBe(1.4)
+ expect(terminalLetterSpacing(1.5)).toBe(1.5)
+ })
+
+ it('clamps out-of-range values to the bounds', () => {
+ expect(terminalLineHeight(0.2)).toBe(TERMINAL_LINE_HEIGHT_MIN)
+ expect(terminalLineHeight(9)).toBe(TERMINAL_LINE_HEIGHT_MAX)
+ expect(terminalLetterSpacing(-40)).toBe(TERMINAL_LETTER_SPACING_MIN)
+ expect(terminalLetterSpacing(40)).toBe(TERMINAL_LETTER_SPACING_MAX)
+ })
+
+ // A hand-edited settings.json can carry anything. NaN would sail through a bare Math.min/max
+ // and reach xterm, which renders a zero-height grid from it.
+ it('falls back to the default for a non-number / NaN', () => {
+ expect(terminalLineHeight(NaN)).toBe(1)
+ expect(terminalLetterSpacing(NaN)).toBe(0)
+ expect(terminalLineHeight(undefined as unknown as number)).toBe(1)
+ expect(terminalLetterSpacing('3' as unknown as number)).toBe(0)
+ })
+})
+
+describe('xtermOptionsFromSettings', () => {
+ it('maps settings onto xterm option names', () => {
+ const o = xtermOptionsFromSettings(
+ visual({
+ fontFamily: 'JetBrains Mono',
+ fontSize: 15,
+ cursorBlink: false,
+ cursorStyle: 'bar',
+ cursorInactiveStyle: 'none',
+ terminalLineHeight: 1.3,
+ terminalLetterSpacing: 0.5
+ })
+ )
+ expect(o.fontFamily).toBe('JetBrains Mono')
+ expect(o.fontSize).toBe(15)
+ expect(o.cursorBlink).toBe(false)
+ expect(o.cursorStyle).toBe('bar')
+ expect(o.cursorInactiveStyle).toBe('none')
+ expect(o.lineHeight).toBe(1.3)
+ expect(o.letterSpacing).toBe(0.5)
+ })
+
+ it('clamps the metrics and the scrollback', () => {
+ const o = xtermOptionsFromSettings(
+ visual({ terminalLineHeight: 99, terminalLetterSpacing: 99, tmuxScrollback: 10 ** 9 })
+ )
+ expect(o.lineHeight).toBe(TERMINAL_LINE_HEIGHT_MAX)
+ expect(o.letterSpacing).toBe(TERMINAL_LETTER_SPACING_MAX)
+ expect(o.scrollback).toBe(XTERM_SCROLLBACK_MAX)
+ })
+
+ it('resolves the theme, tolerating an unknown id', () => {
+ expect(xtermOptionsFromSettings(visual({ terminalTheme: 'nord' })).theme).toBe(
+ resolveTerminalTheme('nord').theme
+ )
+ expect(xtermOptionsFromSettings(visual({ terminalTheme: 'bogus' })).theme).toBe(
+ resolveTerminalTheme('nodeterm-dark').theme
+ )
+ })
+
+ it('carries the non-appearance options both call sites need', () => {
+ const o = xtermOptionsFromSettings(visual())
+ expect(o.allowProposedApi).toBe(true)
+ expect(o.macOptionClickForcesSelection).toBe(true)
+ })
+})
+
+describe('applyLiveOptions', () => {
+ /** An xterm stand-in that records every WRITE to `options` — the guard is the point. */
+ function fakeTerm(s: XtermVisualSettings): LiveOptionTarget & { writes: string[] } {
+ const writes: string[] = []
+ const backing = xtermOptionsFromSettings(s) as unknown as Record<string, unknown>
+ const options = new Proxy(backing, {
+ set(t, k, v) {
+ writes.push(String(k))
+ t[String(k)] = v
+ return true
+ }
+ }) as LiveOptionTarget['options']
+ return { options, writes }
+ }
+
+ it('reports no change and writes nothing when settings are unchanged', () => {
+ const s = visual()
+ const term = fakeTerm(s)
+ expect(applyLiveOptions(term, s)).toEqual({ metricsChanged: false, themeChanged: false })
+ // xterm's `options` is a setter proxy: an unchanged write still fires its change handling,
+ // and terminals are re-optioned on every settings keystroke.
+ expect(term.writes).toEqual([])
+ })
+
+ it('applies a font size change and reports metricsChanged', () => {
+ const term = fakeTerm(visual())
+ const r = applyLiveOptions(term, visual({ fontSize: 16 }))
+ expect(r.metricsChanged).toBe(true)
+ expect(r.themeChanged).toBe(false)
+ expect(term.options.fontSize).toBe(16)
+ expect(term.writes).toEqual(['fontSize'])
+ })
+
+ it.each([
+ ['fontFamily', { fontFamily: 'Iosevka' }],
+ ['lineHeight', { terminalLineHeight: 1.5 }],
+ ['letterSpacing', { terminalLetterSpacing: 2 }]
+ ] as const)('treats %s as a cell-geometry change', (_name, patch) => {
+ const term = fakeTerm(visual())
+ expect(applyLiveOptions(term, visual(patch)).metricsChanged).toBe(true)
+ })
+
+ // The distinction is what decides whether the caller re-fits (and, under co-attach, re-reports
+ // its grid to a SHARED pty). A palette swap must not drag every terminal through a resize.
+ it.each([
+ ['cursorStyle', { cursorStyle: 'bar' }],
+ ['cursorInactiveStyle', { cursorInactiveStyle: 'none' }],
+ ['cursorBlink', { cursorBlink: false }],
+ ['scrollback', { tmuxScrollback: 20000 }],
+ ['theme', { terminalTheme: 'dracula' }]
+ ] as const)('does NOT treat %s as a cell-geometry change', (_name, patch) => {
+ const term = fakeTerm(visual())
+ expect(applyLiveOptions(term, visual(patch as Partial<XtermVisualSettings>)).metricsChanged).toBe(
+ false
+ )
+ })
+
+ it('applies a theme change and reports themeChanged', () => {
+ const term = fakeTerm(visual())
+ const r = applyLiveOptions(term, visual({ terminalTheme: 'tokyo-night' }))
+ expect(r.themeChanged).toBe(true)
+ expect(term.options.theme).toBe(resolveTerminalTheme('tokyo-night').theme)
+ expect(term.writes).toEqual(['theme'])
+ })
+
+ it('an unknown theme id resolves to the default, so it is not a change', () => {
+ const term = fakeTerm(visual())
+ expect(applyLiveOptions(term, visual({ terminalTheme: 'bogus' })).themeChanged).toBe(false)
+ })
+
+ it('applies several changes in one pass', () => {
+ const term = fakeTerm(visual())
+ const r = applyLiveOptions(
+ term,
+ visual({ fontSize: 18, terminalTheme: 'nord', cursorStyle: 'underline' })
+ )
+ expect(r).toEqual({ metricsChanged: true, themeChanged: true })
+ expect(term.options.fontSize).toBe(18)
+ expect(term.options.cursorStyle).toBe('underline')
+ expect(term.options.theme).toBe(resolveTerminalTheme('nord').theme)
+ })
+})
diff --git a/src/renderer/terminal/terminal-config.ts b/src/renderer/terminal/terminal-config.ts
index 6cb0c270e..56103a542 100644
--- a/src/renderer/terminal/terminal-config.ts
+++ b/src/renderer/terminal/terminal-config.ts
@@ -1,4 +1,7 @@
+import type { ITheme } from '@xterm/xterm'
import type { ClientId } from '@shared/presence'
+import type { Settings, TerminalCursorInactiveStyle, TerminalCursorStyle } from '@shared/types'
+import { resolveTerminalTheme } from './themes'
/**
* Pure decisions behind the xterm instance in `TerminalNode` — extracted so they can be tested
@@ -156,6 +159,159 @@ export function xtermScrollback(tmuxScrollback: number): number {
return Math.min(Math.max(XTERM_SCROLLBACK_MIN, tmuxScrollback), XTERM_SCROLLBACK_MAX)
}
+/* ------------------------------------------------------------------------------------------- *
+ * Terminal appearance — ONE source for both xterm call sites.
+ *
+ * `TerminalNode` (the canvas) and `ModalTerminal` (the kanban card modal) each build an xterm for
+ * the same session, and they had drifted apart: two different hardcoded backgrounds, and only the
+ * canvas one applied setting changes to a live terminal. Every appearance option now flows through
+ * `xtermOptionsFromSettings` (mount) and `applyLiveOptions` (change), so a new option cannot land
+ * on one surface only.
+ * ------------------------------------------------------------------------------------------- */
+
+/** Line height as a multiple of the font size. Below 1 xterm clips glyph descenders; above 2 the
+ * grid is mostly air and a full-screen TUI stops fitting anything useful. */
+export const TERMINAL_LINE_HEIGHT_MIN = 1
+export const TERMINAL_LINE_HEIGHT_MAX = 2
+/** Extra px between cells. Negative tightens; past these bounds box-drawing characters (which
+ * agent CLIs draw their frames with) stop meeting and the output looks torn. */
+export const TERMINAL_LETTER_SPACING_MIN = -2
+export const TERMINAL_LETTER_SPACING_MAX = 4
+
+function clamp(value: number, min: number, max: number, fallback: number): number {
+ // settings.json is hand-editable: a missing/NaN value must land on the default, not on NaN —
+ // which xterm would happily accept and then render a zero-height grid from.
+ if (typeof value !== 'number' || !Number.isFinite(value)) return fallback
+ return Math.min(Math.max(min, value), max)
+}
+
+export function terminalLineHeight(value: number): number {
+ return clamp(value, TERMINAL_LINE_HEIGHT_MIN, TERMINAL_LINE_HEIGHT_MAX, 1)
+}
+
+export function terminalLetterSpacing(value: number): number {
+ return clamp(value, TERMINAL_LETTER_SPACING_MIN, TERMINAL_LETTER_SPACING_MAX, 0)
+}
+
+/** The slice of `Settings` that decides how a terminal LOOKS. Narrowed to a structural type so
+ * the helpers below are callable from a test with a plain object literal. */
+export type XtermVisualSettings = Pick<
+ Settings,
+ | 'fontFamily'
+ | 'fontSize'
+ | 'cursorBlink'
+ | 'cursorStyle'
+ | 'cursorInactiveStyle'
+ | 'terminalLineHeight'
+ | 'terminalLetterSpacing'
+ | 'terminalTheme'
+ | 'tmuxScrollback'
+>
+
+/** The appearance-derived options, resolved and clamped. */
+export interface XtermVisualOptions {
+ fontFamily: string
+ fontSize: number
+ cursorBlink: boolean
+ cursorStyle: TerminalCursorStyle
+ cursorInactiveStyle: TerminalCursorInactiveStyle
+ lineHeight: number
+ letterSpacing: number
+ scrollback: number
+ theme: ITheme
+}
+
+/**
+ * Every appearance option for a `new Terminal({...})`, from settings.
+ *
+ * The non-appearance options both call sites also need (`allowProposedApi`,
+ * `macOptionClickForcesSelection`) are included so a call site is a spread of this and nothing
+ * else — the point is that there is no per-site options literal left to drift.
+ */
+export function xtermOptionsFromSettings(
+ s: XtermVisualSettings
+): XtermVisualOptions & { allowProposedApi: true; macOptionClickForcesSelection: true } {
+ return {
+ fontFamily: s.fontFamily,
+ fontSize: s.fontSize,
+ cursorBlink: s.cursorBlink,
+ cursorStyle: s.cursorStyle,
+ cursorInactiveStyle: s.cursorInactiveStyle,
+ lineHeight: terminalLineHeight(s.terminalLineHeight),
+ letterSpacing: terminalLetterSpacing(s.terminalLetterSpacing),
+ // NOT what the user scrolls in a tmux session — tmux's mouse is ON and the wheel scrolls
+ // tmux's own history (see pty-manager's tmuxConf). This buffer backs the plain-shell
+ // fallback (tmux unavailable) and the cold-snapshot replay. Capped: per node, many nodes.
+ scrollback: xtermScrollback(s.tmuxScrollback),
+ theme: resolveTerminalTheme(s.terminalTheme).theme,
+ allowProposedApi: true,
+ // Inside an app that requested mouse tracking (vim, htop) a plain drag goes to the app;
+ // Option/Alt forces a selection instead (Shift does the same via xterm's own bypass).
+ macOptionClickForcesSelection: true
+ }
+}
+
+/** Just enough of an xterm instance to re-option it — keeps this file testable without a DOM. */
+export interface LiveOptionTarget {
+ options: Partial<XtermVisualOptions>
+}
+
+/** What the caller still owes after a live re-option. */
+export interface LiveOptionEffects {
+ /**
+ * The CELL GEOMETRY changed, so this terminal now fits a different grid and the caller MUST
+ * re-fit — routing the change through the same path a container resize takes, so the pty is
+ * told the new size. Skipping it leaves the pty running at a grid nobody renders, and under
+ * co-attach (one pty, N subscribers) it is worse than cosmetic: this client keeps clamping the
+ * SHARED pty to its pre-change size, so a font tweak here shrinks somebody else's terminal.
+ */
+ metricsChanged: boolean
+ /**
+ * The palette changed. xterm repaints on its own, but the renderer swap / detached-element
+ * cases can swallow a full refresh (see `TerminalNode`'s `fullRepaint`), and a half-repainted
+ * palette is the most visible possible failure — so the caller forces one repaint.
+ */
+ themeChanged: boolean
+}
+
+/**
+ * Apply appearance settings to a LIVE terminal, reporting what the caller still owes.
+ *
+ * Assignment is per-option and guarded by a comparison, because xterm's `options` is a setter
+ * proxy: writing an unchanged value still fires its change handling (and, for `theme`, a full
+ * palette rebuild). Terminals are re-optioned on every settings keystroke, so the guard is what
+ * keeps a slider drag from thrashing every terminal on the canvas.
+ */
+export function applyLiveOptions(
+ term: LiveOptionTarget,
+ s: XtermVisualSettings
+): LiveOptionEffects {
+ const next = xtermOptionsFromSettings(s)
+ const o = term.options
+ const metricsChanged =
+ o.fontFamily !== next.fontFamily ||
+ o.fontSize !== next.fontSize ||
+ o.lineHeight !== next.lineHeight ||
+ o.letterSpacing !== next.letterSpacing
+ // Identity, not deep equality: themes are frozen module constants, so the same id always yields
+ // the same object and a changed id never does.
+ const themeChanged = o.theme !== next.theme
+
+ if (o.fontFamily !== next.fontFamily) o.fontFamily = next.fontFamily
+ if (o.fontSize !== next.fontSize) o.fontSize = next.fontSize
+ if (o.lineHeight !== next.lineHeight) o.lineHeight = next.lineHeight
+ if (o.letterSpacing !== next.letterSpacing) o.letterSpacing = next.letterSpacing
+ if (o.cursorBlink !== next.cursorBlink) o.cursorBlink = next.cursorBlink
+ if (o.cursorStyle !== next.cursorStyle) o.cursorStyle = next.cursorStyle
+ if (o.cursorInactiveStyle !== next.cursorInactiveStyle) {
+ o.cursorInactiveStyle = next.cursorInactiveStyle
+ }
+ if (o.scrollback !== next.scrollback) o.scrollback = next.scrollback
+ if (themeChanged) o.theme = next.theme
+
+ return { metricsChanged, themeChanged }
+}
+
/**
* What a freshly-created xterm has to be seeded with when its session resolves:
* - `cold-snapshot` — the tmux session is GONE (first open after a machine reboot, which kills the
diff --git a/src/renderer/terminal/themes.test.ts b/src/renderer/terminal/themes.test.ts
new file mode 100644
index 000000000..689451c61
--- /dev/null
+++ b/src/renderer/terminal/themes.test.ts
@@ -0,0 +1,117 @@
+import { describe, it, expect } from 'vitest'
+import {
+ DEFAULT_TERMINAL_THEME_ID,
+ TERMINAL_THEMES,
+ resolveTerminalTheme
+} from './themes'
+
+const ANSI_KEYS = [
+ 'black',
+ 'red',
+ 'green',
+ 'yellow',
+ 'blue',
+ 'magenta',
+ 'cyan',
+ 'white',
+ 'brightBlack',
+ 'brightRed',
+ 'brightGreen',
+ 'brightYellow',
+ 'brightBlue',
+ 'brightMagenta',
+ 'brightCyan',
+ 'brightWhite'
+] as const
+
+describe('TERMINAL_THEMES', () => {
+ it('has unique ids', () => {
+ const ids = TERMINAL_THEMES.map((t) => t.id)
+ expect(new Set(ids).size).toBe(ids.length)
+ })
+
+ it('includes the default id', () => {
+ expect(TERMINAL_THEMES.some((t) => t.id === DEFAULT_TERMINAL_THEME_ID)).toBe(true)
+ })
+
+ // A theme missing an ANSI slot doesn't fail loudly — xterm silently falls back to ITS default
+ // for that one colour, so e.g. a Solarized terminal renders one Tango-green among eight
+ // Solarized ones. Only a full-palette check catches that.
+ it.each(TERMINAL_THEMES.map((t) => [t.id, t] as const))(
+ '%s defines a complete palette',
+ (_id, t) => {
+ for (const key of ANSI_KEYS) {
+ expect(t.theme[key], `${t.id}.${key}`).toMatch(/^#[0-9a-f]{6}$/i)
+ }
+ expect(t.theme.background, `${t.id}.background`).toMatch(/^#[0-9a-f]{6}$/i)
+ expect(t.theme.foreground, `${t.id}.foreground`).toMatch(/^#[0-9a-f]{6}$/i)
+ expect(t.theme.cursor, `${t.id}.cursor`).toMatch(/^#[0-9a-f]{6}$/i)
+ expect(t.theme.cursorAccent, `${t.id}.cursorAccent`).toMatch(/^#[0-9a-f]{6}$/i)
+ expect(t.theme.selectionBackground, `${t.id}.selectionBackground`).toMatch(
+ /^#[0-9a-f]{6,8}$/i
+ )
+ }
+ )
+
+ it('has a non-empty label for every theme', () => {
+ for (const t of TERMINAL_THEMES) expect(t.label.trim().length).toBeGreaterThan(0)
+ })
+
+ it('offers at least one light theme', () => {
+ expect(TERMINAL_THEMES.some((t) => !t.dark)).toBe(true)
+ })
+})
+
+describe('the default theme reproduces the pre-themes appearance', () => {
+ // LOAD-BEARING. Before themes, both call sites hardcoded these two colours and let xterm fill
+ // in the rest from its own (Tango) palette. Anyone who never picks a theme must keep seeing
+ // exactly that — an update is not allowed to repaint their terminals. Changing these values
+ // means deciding to do that on purpose.
+ const d = resolveTerminalTheme(DEFAULT_TERMINAL_THEME_ID).theme
+
+ it('keeps the hardcoded background and foreground', () => {
+ expect(d.background).toBe('#1e1e1e')
+ expect(d.foreground).toBe('#e6e6e6')
+ })
+
+ it("keeps xterm's own default ANSI palette", () => {
+ expect(d.black).toBe('#2e3436')
+ expect(d.red).toBe('#cc0000')
+ expect(d.green).toBe('#4e9a06')
+ expect(d.yellow).toBe('#c4a000')
+ expect(d.blue).toBe('#3465a4')
+ expect(d.magenta).toBe('#75507b')
+ expect(d.cyan).toBe('#06989a')
+ expect(d.white).toBe('#d3d7cf')
+ expect(d.brightBlack).toBe('#555753')
+ expect(d.brightRed).toBe('#ef2929')
+ expect(d.brightGreen).toBe('#8ae234')
+ expect(d.brightYellow).toBe('#fce94f')
+ expect(d.brightBlue).toBe('#729fcf')
+ expect(d.brightMagenta).toBe('#ad7fa8')
+ expect(d.brightCyan).toBe('#34e2e2')
+ expect(d.brightWhite).toBe('#eeeeec')
+ })
+})
+
+describe('resolveTerminalTheme', () => {
+ it('resolves a known id', () => {
+ expect(resolveTerminalTheme('dracula').id).toBe('dracula')
+ })
+
+ // settings.json is hand-editable and travels between versions. Handing xterm an undefined theme
+ // would drop the terminal to xterm's own black background — a visibly broken app from a typo.
+ it('falls back to the default for an unknown id', () => {
+ expect(resolveTerminalTheme('no-such-theme').id).toBe(DEFAULT_TERMINAL_THEME_ID)
+ })
+
+ it('falls back for undefined and empty input', () => {
+ expect(resolveTerminalTheme(undefined).id).toBe(DEFAULT_TERMINAL_THEME_ID)
+ expect(resolveTerminalTheme('').id).toBe(DEFAULT_TERMINAL_THEME_ID)
+ })
+
+ // `applyLiveOptions` detects a palette change by object identity, so resolution must be stable.
+ it('returns the same object for the same id', () => {
+ expect(resolveTerminalTheme('nord').theme).toBe(resolveTerminalTheme('nord').theme)
+ })
+})
diff --git a/src/renderer/terminal/themes.ts b/src/renderer/terminal/themes.ts
new file mode 100644
index 000000000..606ee05a1
--- /dev/null
+++ b/src/renderer/terminal/themes.ts
@@ -0,0 +1,323 @@
+import type { ITheme } from '@xterm/xterm'
+
+/**
+ * Terminal colour schemes.
+ *
+ * Pure data + one resolver, deliberately free of xterm runtime imports (the `ITheme` import is
+ * type-only, so this module loads in the node test environment). Everything that turns a theme
+ * into xterm options lives in `terminal-config.ts`.
+ *
+ * The contract that makes this safe to ship: **`nodeterm-dark` must render exactly what the app
+ * rendered before themes existed.** Both terminal call sites used to hardcode
+ * `{ background: '#1e1e1e', foreground: '#e6e6e6' }` and let xterm fill in the rest, so the
+ * default theme carries those two colours plus xterm's own default ANSI palette (Tango) spelled
+ * out. `themes.test.ts` locks that down — an "improvement" to those 18 values silently repaints
+ * every existing user's terminals on update.
+ */
+
+export interface TerminalTheme {
+ id: string
+ label: string
+ /** Whether the scheme is dark — groups the picker, and is what a light theme needs to declare
+ * so the surrounding node chrome can stay legible against it. */
+ dark: boolean
+ theme: ITheme
+}
+
+export const DEFAULT_TERMINAL_THEME_ID = 'nodeterm-dark'
+
+export const TERMINAL_THEMES: readonly TerminalTheme[] = [
+ {
+ id: 'nodeterm-dark',
+ label: 'nodeterm Dark',
+ dark: true,
+ theme: {
+ background: '#1e1e1e',
+ foreground: '#e6e6e6',
+ cursor: '#ffffff',
+ cursorAccent: '#1e1e1e',
+ selectionBackground: '#ffffff4d',
+ // xterm's built-in default palette (Tango) — see the module comment.
+ black: '#2e3436',
+ red: '#cc0000',
+ green: '#4e9a06',
+ yellow: '#c4a000',
+ blue: '#3465a4',
+ magenta: '#75507b',
+ cyan: '#06989a',
+ white: '#d3d7cf',
+ brightBlack: '#555753',
+ brightRed: '#ef2929',
+ brightGreen: '#8ae234',
+ brightYellow: '#fce94f',
+ brightBlue: '#729fcf',
+ brightMagenta: '#ad7fa8',
+ brightCyan: '#34e2e2',
+ brightWhite: '#eeeeec'
+ }
+ },
+ {
+ id: 'dracula',
+ label: 'Dracula',
+ dark: true,
+ theme: {
+ background: '#282a36',
+ foreground: '#f8f8f2',
+ cursor: '#f8f8f2',
+ cursorAccent: '#282a36',
+ selectionBackground: '#44475a',
+ black: '#21222c',
+ red: '#ff5555',
+ green: '#50fa7b',
+ yellow: '#f1fa8c',
+ blue: '#bd93f9',
+ magenta: '#ff79c6',
+ cyan: '#8be9fd',
+ white: '#f8f8f2',
+ brightBlack: '#6272a4',
+ brightRed: '#ff6e6e',
+ brightGreen: '#69ff94',
+ brightYellow: '#ffffa5',
+ brightBlue: '#d6acff',
+ brightMagenta: '#ff92df',
+ brightCyan: '#a4ffff',
+ brightWhite: '#ffffff'
+ }
+ },
+ {
+ id: 'tokyo-night',
+ label: 'Tokyo Night',
+ dark: true,
+ theme: {
+ background: '#1a1b26',
+ foreground: '#c0caf5',
+ cursor: '#c0caf5',
+ cursorAccent: '#1a1b26',
+ selectionBackground: '#33467c',
+ black: '#15161e',
+ red: '#f7768e',
+ green: '#9ece6a',
+ yellow: '#e0af68',
+ blue: '#7aa2f7',
+ magenta: '#bb9af7',
+ cyan: '#7dcfff',
+ white: '#a9b1d6',
+ brightBlack: '#414868',
+ brightRed: '#ff7a93',
+ brightGreen: '#b9f27c',
+ brightYellow: '#ff9e64',
+ brightBlue: '#7da6ff',
+ brightMagenta: '#bb9af7',
+ brightCyan: '#0db9d7',
+ brightWhite: '#c0caf5'
+ }
+ },
+ {
+ id: 'catppuccin-mocha',
+ label: 'Catppuccin Mocha',
+ dark: true,
+ theme: {
+ background: '#1e1e2e',
+ foreground: '#cdd6f4',
+ cursor: '#f5e0dc',
+ cursorAccent: '#1e1e2e',
+ selectionBackground: '#585b70',
+ black: '#45475a',
+ red: '#f38ba8',
+ green: '#a6e3a1',
+ yellow: '#f9e2af',
+ blue: '#89b4fa',
+ magenta: '#f5c2e7',
+ cyan: '#94e2d5',
+ white: '#bac2de',
+ brightBlack: '#585b70',
+ brightRed: '#f38ba8',
+ brightGreen: '#a6e3a1',
+ brightYellow: '#f9e2af',
+ brightBlue: '#89b4fa',
+ brightMagenta: '#f5c2e7',
+ brightCyan: '#94e2d5',
+ brightWhite: '#a6adc8'
+ }
+ },
+ {
+ id: 'gruvbox-dark',
+ label: 'Gruvbox Dark',
+ dark: true,
+ theme: {
+ background: '#282828',
+ foreground: '#ebdbb2',
+ cursor: '#ebdbb2',
+ cursorAccent: '#282828',
+ selectionBackground: '#504945',
+ black: '#282828',
+ red: '#cc241d',
+ green: '#98971a',
+ yellow: '#d79921',
+ blue: '#458588',
+ magenta: '#b16286',
+ cyan: '#689d6a',
+ white: '#a89984',
+ brightBlack: '#928374',
+ brightRed: '#fb4934',
+ brightGreen: '#b8bb26',
+ brightYellow: '#fabd2f',
+ brightBlue: '#83a598',
+ brightMagenta: '#d3869b',
+ brightCyan: '#8ec07c',
+ brightWhite: '#ebdbb2'
+ }
+ },
+ {
+ id: 'nord',
+ label: 'Nord',
+ dark: true,
+ theme: {
+ background: '#2e3440',
+ foreground: '#d8dee9',
+ cursor: '#d8dee9',
+ cursorAccent: '#2e3440',
+ selectionBackground: '#434c5e',
+ black: '#3b4252',
+ red: '#bf616a',
+ green: '#a3be8c',
+ yellow: '#ebcb8b',
+ blue: '#81a1c1',
+ magenta: '#b48ead',
+ cyan: '#88c0d0',
+ white: '#e5e9f0',
+ brightBlack: '#4c566a',
+ brightRed: '#bf616a',
+ brightGreen: '#a3be8c',
+ brightYellow: '#ebcb8b',
+ brightBlue: '#81a1c1',
+ brightMagenta: '#b48ead',
+ brightCyan: '#8fbcbb',
+ brightWhite: '#eceff4'
+ }
+ },
+ {
+ id: 'one-dark',
+ label: 'One Dark',
+ dark: true,
+ theme: {
+ background: '#282c34',
+ foreground: '#abb2bf',
+ cursor: '#528bff',
+ cursorAccent: '#282c34',
+ selectionBackground: '#3e4451',
+ black: '#282c34',
+ red: '#e06c75',
+ green: '#98c379',
+ yellow: '#e5c07b',
+ blue: '#61afef',
+ magenta: '#c678dd',
+ cyan: '#56b6c2',
+ white: '#abb2bf',
+ brightBlack: '#5c6370',
+ brightRed: '#e06c75',
+ brightGreen: '#98c379',
+ brightYellow: '#e5c07b',
+ brightBlue: '#61afef',
+ brightMagenta: '#c678dd',
+ brightCyan: '#56b6c2',
+ brightWhite: '#ffffff'
+ }
+ },
+ {
+ id: 'solarized-dark',
+ label: 'Solarized Dark',
+ dark: true,
+ theme: {
+ background: '#002b36',
+ foreground: '#839496',
+ cursor: '#93a1a1',
+ cursorAccent: '#002b36',
+ selectionBackground: '#073642',
+ black: '#073642',
+ red: '#dc322f',
+ green: '#859900',
+ yellow: '#b58900',
+ blue: '#268bd2',
+ magenta: '#d33682',
+ cyan: '#2aa198',
+ white: '#eee8d5',
+ brightBlack: '#586e75',
+ brightRed: '#cb4b16',
+ brightGreen: '#657b83',
+ brightYellow: '#839496',
+ brightBlue: '#93a1a1',
+ brightMagenta: '#6c71c4',
+ brightCyan: '#a1a1a1',
+ brightWhite: '#fdf6e3'
+ }
+ },
+ {
+ id: 'catppuccin-latte',
+ label: 'Catppuccin Latte',
+ dark: false,
+ theme: {
+ background: '#eff1f5',
+ foreground: '#4c4f69',
+ cursor: '#dc8a78',
+ cursorAccent: '#eff1f5',
+ selectionBackground: '#acb0be',
+ black: '#5c5f77',
+ red: '#d20f39',
+ green: '#40a02b',
+ yellow: '#df8e1d',
+ blue: '#1e66f5',
+ magenta: '#ea76cb',
+ cyan: '#179299',
+ white: '#acb0be',
+ brightBlack: '#6c6f85',
+ brightRed: '#d20f39',
+ brightGreen: '#40a02b',
+ brightYellow: '#df8e1d',
+ brightBlue: '#1e66f5',
+ brightMagenta: '#ea76cb',
+ brightCyan: '#179299',
+ brightWhite: '#bcc0cc'
+ }
+ },
+ {
+ id: 'solarized-light',
+ label: 'Solarized Light',
+ dark: false,
+ theme: {
+ background: '#fdf6e3',
+ foreground: '#657b83',
+ cursor: '#586e75',
+ cursorAccent: '#fdf6e3',
+ selectionBackground: '#eee8d5',
+ black: '#073642',
+ red: '#dc322f',
+ green: '#859900',
+ yellow: '#b58900',
+ blue: '#268bd2',
+ magenta: '#d33682',
+ cyan: '#2aa198',
+ white: '#eee8d5',
+ brightBlack: '#586e75',
+ brightRed: '#cb4b16',
+ brightGreen: '#93a1a1',
+ brightYellow: '#839496',
+ brightBlue: '#268bd2',
+ brightMagenta: '#6c71c4',
+ brightCyan: '#2aa198',
+ brightWhite: '#002b36'
+ }
+ }
+]
+
+const BY_ID = new Map(TERMINAL_THEMES.map((t) => [t.id, t]))
+
+/**
+ * Resolve a stored theme id. TOLERANT by design: `settings.json` is hand-editable and travels
+ * between versions, so an unknown id (a theme we removed, a typo) must degrade to the default
+ * rather than hand xterm an `undefined` theme — which would drop the terminal to xterm's own
+ * black background, i.e. a visibly broken app for a one-word mistake.
+ */
+export function resolveTerminalTheme(id: string | undefined): TerminalTheme {
+ return (id ? BY_ID.get(id) : undefined) ?? BY_ID.get(DEFAULT_TERMINAL_THEME_ID)!
+}
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 57949ef17..95d012761 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -674,11 +674,29 @@ export interface SpeechSettings {
shortcut: string
}
+/** xterm cursor shapes, mirrored here so `Settings` doesn't depend on the xterm typings (which
+ * are renderer-only — `src/shared` is imported by main and the server shell too). */
+export type TerminalCursorStyle = 'block' | 'bar' | 'underline'
+export type TerminalCursorInactiveStyle = TerminalCursorStyle | 'outline' | 'none'
+
/** User-configurable application settings (settings.json). */
export interface Settings {
fontSize: number
fontFamily: string
cursorBlink: boolean
+ /** Terminal colour scheme — an id from `renderer/terminal/themes.ts`. Resolution is tolerant
+ * (settings.json is hand-editable): an unknown id falls back to the default theme, whose
+ * colours reproduce the pre-feature hardcoded `#1e1e1e`/`#e6e6e6` exactly. */
+ terminalTheme: string
+ /** Cursor shape. */
+ cursorStyle: TerminalCursorStyle
+ /** Cursor shape while the terminal does NOT have focus. `outline` (xterm's own default) is what
+ * tells you at a glance which of a canvas full of terminals is taking your keystrokes. */
+ cursorInactiveStyle: TerminalCursorInactiveStyle
+ /** Line height as a multiple of the font size (1 = xterm's default, i.e. no extra leading). */
+ terminalLineHeight: number
+ /** Extra horizontal space between cells, in CSS pixels (0 = xterm's default). */
+ terminalLetterSpacing: number
/** Empty string = use the system default shell. */
defaultShell: string
gridSize: number
@@ -822,6 +840,14 @@ export const DEFAULT_SETTINGS: Settings = {
fontSize: 13,
fontFamily: 'Menlo, Monaco, "Courier New", monospace',
cursorBlink: true,
+ // Every appearance default below reproduces the pre-feature look bit-for-bit: the default theme
+ // carries the old hardcoded background/foreground, and block/outline/1/0 are xterm's own
+ // defaults. Picking a theme is opt-in — an update must not repaint anybody's terminals.
+ terminalTheme: 'nodeterm-dark',
+ cursorStyle: 'block',
+ cursorInactiveStyle: 'outline',
+ terminalLineHeight: 1,
+ terminalLetterSpacing: 0,
defaultShell: '',
gridSize: 24,
snapToGrid: false,