feat(desktop): pick a terminal theme from the right-click menu
TH
24d ago+1901+1901+0123456789012345678901234567890123456789-21-21-01234567890123456789
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_idcolumn onterminal_sessions(migration0037, generated with drizzle-kit), aterminal.setThememutation with the same NOT_FOUND and workspace checks asrename, andthemeIdon the create and list paths. The create paths writethemeIdonly 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.
useTerminalAppearancetakes an optional session theme, andCOLORFGBGfollows 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 withsetThemeonce the session appears. - docs: a "Per-Terminal Themes" section in
custom-themes.mdx.
Two things I'd like a maintainer's call on:
- 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.
setThemeupdates 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 lintandbun run typecheckpass.- New
terminal.theme.test.tsin 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.
Checklist
- PR title follows conventional commits (
type(scope): subject) -
bun run lintandbun run typecheckpass (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_idcolumn onterminal_sessions(migration0039); 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
setThemeonce 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.
setThemeupdates 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.