feat(desktop): pick a terminal theme from the right-click menu

TH
24d ago
+1901-21

What & why

Closes #7905.

Every terminal pane uses the app theme, so you can't give one terminal its own colors. This adds a Theme submenu to the terminal's right-click menu with App theme, Light, Dark, and Custom groups. The choice applies to that terminal only.

The theme is stored on the terminal session in the host-service, next to custom_title, so it survives restarts and reattaching:

  • host-service: a nullable theme_id column on terminal_sessions (migration 0037, generated with drizzle-kit), a terminal.setTheme mutation with the same NOT_FOUND and workspace checks as rename, and themeId on the create and list paths. The create paths write themeId only when the row is inserted, so relaunching or adopting a session keeps its theme.
  • desktop: the submenu is built when the menu opens, from the cached session list and the theme store, so the pane registry doesn't rebuild on every list refetch. useTerminalAppearance takes an optional session theme, and COLORFGBG follows the terminal's theme instead of the app theme. A theme picked before the session shows up in the session list is kept on the pane and saved with setTheme once the session appears.
  • docs: a "Per-Terminal Themes" section in custom-themes.mdx.

Two things I'd like a maintainer's call on:

  1. Custom themes live on one desktop. If a session points at a custom theme that another client doesn't have, or that was deleted, the terminal falls back to the app theme and the menu marks "App theme". If you'd rather limit per-terminal themes to built-in ones, that's a small change.
  2. setTheme updates the in-memory session and refreshes the list for the client that made the change, but it doesn't broadcast. A second attached client picks it up on its next list poll. A broadcast needs a new message type on both sides, so I left it for a follow-up.

How I tested it

  • bun run lint and bun run typecheck pass.
  • New terminal.theme.test.ts in host-service: set and clear a theme, reject another workspace (FORBIDDEN), reject an unknown terminal (NOT_FOUND).
  • Existing desktop v2-workspace tests and host-service terminal tests pass.
  • In the dev app: right-click a terminal, open Theme, pick a theme. Screenshot below.
image

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass (CI fails on lint warnings too)
  • "Allow edits from maintainers" is checked on fork PRs

Summary by cubic

Adds a Theme submenu to the terminal's right-click menu so each terminal can use its own colors instead of following the app theme. The choice is stored on the terminal session in the host-service, so it survives restarts, detaching, and reattaching.

Notes

  • The theme is stored as a nullable theme_id column on terminal_sessions (migration 0039); create writes it only on insert, so relaunching or adopting a session keeps its theme.
  • The submenu is hidden on host versions that predate terminal.setTheme. A session pointing at a custom theme that isn't on the current client falls back to the app theme, and the menu marks "App theme".
  • A theme picked while the terminal is still starting is sent with the create request, then synced with setTheme once the session appears; the pending choice wins until the sync finishes so colors don't flicker. "App theme" is stored as null, distinct from no pending choice.
  • Pending saves are serialized and guarded by terminal id, and a failed save shows a toast and clears its pending state.
  • setTheme updates the session list for the client that made the change but doesn't broadcast; a second attached client picks it up on its next list poll. Broadcasting needs a new message type on both sides.
  • Theme IDs are capped at 200 characters across import validation and host-side persistence to keep the terminal query string safe.

Summary by CodeRabbit

  • New Features
    • Choose a theme for each terminal session from its context menu, including Light, Dark, custom themes, or the app theme.
    • Terminal theme choices persist across tab switches, detaching, and app restarts. Sessions fall back to the app theme if a selected custom theme is removed.
  • Documentation
    • Added guidance on choosing and persisting per-terminal themes.