Themes & Ghostty config
ghostty-webgpu represents colors as explicit { r, g, b } integer objects and passes them directly to libghostty-vt and the renderers. That avoids CSS color parsing on the frame path and keeps palette lookups identical across WebGPU, WebGL2, Canvas 2D, and DOM.
You will learn
How to structure and apply a
TerminalThemewithout breaking the 256-color palette- How to batch theme, font, cursor, and opacity changes into one atomic repaint
How
backgroundOpacityinteracts with explicit SGR cell backgroundsHow to load a user’s local Ghostty configuration file on the server with
ghostty-webgpu/config-resolver
Apply a theme
Section titled “Apply a theme”import type { Terminal } from 'ghostty-webgpu'
export function applyTheme(terminal: Terminal) { terminal.setTheme({ ...terminal.appearance.theme, background: { r: 21, g: 19, b: 31 }, foreground: { r: 230, g: 226, b: 247 }, cursor: { r: 126, g: 230, b: 206 }, selectionBackground: { r: 62, g: 58, b: 92 }, selectionForeground: { r: 230, g: 226, b: 247 }, })}TerminalTheme includes the named UI colors (background, foreground, cursor, selectionBackground, selectionForeground, optional cursorText), minimumContrast, and a palette array of 256 RGB entries.
Set minimumContrast above 1 to enforce a minimum WCAG contrast ratio between a cell’s resolved foreground and background colors (default 1 leaves colors untouched).
Batch appearance updates
Section titled “Batch appearance updates”When several visual properties change together (for example, switching between a dark and light app theme), call terminal.setAppearance({ theme, font, cursor, backgroundOpacity, colorScheme }). That commits one atomic revision and triggers a single repaint instead of repainting once per setter. On ghostty-webgpu/worker, all appearance setters return promises.
Background opacity and backdrops
Section titled “Background opacity and backdrops”The root .ghostty-webgpu element paints the default theme background across the entire container (including padding and remainder pixels outside the cell grid), while renderers leave default-background cells transparent.
- Set
backgroundOpacityin[0, 1](default1, matching Ghostty’sbackground-opacity) to fade that root fill and let a page backdrop show through. - Set
backgroundOpacity: 0if your page paints its own surface behind the terminal. - Cells with an explicit SGR background color stay opaque so TUI panels and status bars remain readable.
Resolve a host Ghostty config
Section titled “Resolve a host Ghostty config”ghostty-webgpu/config-resolver runs in Node or Bun and invokes a native helper binary on macOS (darwin-arm64, darwin-x64) and Linux (linux-arm64, linux-x64) to parse a user’s Ghostty config file into a structured appearance object (including surface.backgroundOpacity and light/dark profiles).
Keep ghostty-webgpu/config-resolver strictly on the server and send only the resolved appearance JSON to the browser client.
Native helper packaging and bootstrap checkouts
Source checkouts carry only the bootstrap manifest until the platform helper binaries are assembled. The browser terminal does not depend on ghostty-webgpu/config-resolver and runs independently without it. See the config resolver guide and Config resolver API for setup and manifest verification.
Recap
Spread
terminal.appearance.themewhen changing named colors so the 256-entry RGB palette stays valid.Use
setAppearance()to apply theme, font, cursor, andbackgroundOpacitychanges in a single repaint.Run
ghostty-webgpu/config-resolveron the server only and forward the resolved JSON to the browser.