Skip to content

Commit e298396

Browse files
committed
docs: add colorscheme OpenCode design
1 parent 2708754 commit e298396

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Colorscheme OpenCode Integration Design
2+
3+
## Goal
4+
5+
Make `cs` switch OpenCode's terminal UI theme through its official TUI
6+
configuration, while making the existing multi-application theme switcher safer
7+
and easier to maintain. Preserve the current selector names and the existing
8+
theme behaviour for all other tools.
9+
10+
## Scope
11+
12+
- Keep the six existing profiles: `catppuccin_mocha`, `tokyonight_moon`,
13+
`nord`, `onedark`, `dracula`, and `gruvbox_dark`.
14+
- Refactor `conf/zsh/fun/colorscheme.zsh` so per-tool theme aliases are held in
15+
one centralized profile mapping rather than scattered `case` statements.
16+
- Add OpenCode's tracked TUI `theme` setting to `conf/opencode/tui.json`.
17+
- Update OpenCode through `~/.config/opencode/tui.json`, not
18+
`opencode.jsonc`.
19+
- Validate the selected profile, required configuration files, and external
20+
theme assets before changing any configuration.
21+
- Use temporary files and atomic replacement for rewritten configuration files.
22+
- Preserve the existing tmux reload and clearly report that other applications,
23+
including OpenCode, must be restarted to display the new theme.
24+
25+
## Non-goals
26+
27+
- Do not change the set of selectable profiles.
28+
- Do not change OpenCode providers, credentials, agents, MCPs, permissions, or
29+
plugins.
30+
- Do not reconcile the separate plugin declarations in `opencode.jsonc` and
31+
`tui.json`.
32+
- Do not add desktop, archived, or unrelated application themes to `cs`.
33+
- Do not implement live reload for applications that do not support it.
34+
35+
## Theme mapping
36+
37+
The profile name remains the default alias for tools whose asset names already
38+
match it. Explicit aliases are defined only where a consumer uses a different
39+
identifier.
40+
41+
| Profile | Neovim | Yazi | eza | OpenCode |
42+
| --- | --- | --- | --- | --- |
43+
| `catppuccin_mocha` | `catppuccin-nvim` | `catppuccin-mocha` | `catppuccin` | `catppuccin` |
44+
| `tokyonight_moon` | `tokyonight` | `tokyo-night` | `tokyonight` | `tokyonight` |
45+
| `nord` | `nordic` | `nord` | `nord` | `nord` |
46+
| `onedark` | `onedark` | `onedark` | `onedark` | `one-dark` |
47+
| `dracula` | `dracula` | `dracula` | `dracula` | `dracula` |
48+
| `gruvbox_dark` | `gruvbox` | `gruvbox-dark` | `gruvbox-dark` | `gruvbox` |
49+
50+
OpenCode's `catppuccin` built-in theme is its Mocha palette. The distinct
51+
`catppuccin-macchiato` theme is deliberately not used for the Mocha profile.
52+
53+
## Switch flow
54+
55+
1. `cs` shows the current profile and prompts from the existing six-item list.
56+
2. `modify_scheme` rejects an empty or unknown profile before making changes.
57+
3. It resolves all consumer aliases from the central mapping and verifies that
58+
every target configuration file exists. It additionally checks the selected
59+
eza, tmux, and Lazygit theme files.
60+
4. It stages textual updates in temporary files beside their targets:
61+
Starship palette, Neovim colorscheme, Yazi dark flavor, bat theme, tmux theme
62+
source, Lazygit theme block, Git Delta syntax theme, and OpenCode TUI theme.
63+
5. The OpenCode update targets the top-level `theme` property in
64+
`~/.config/opencode/tui.json`; the tracked file contains the property from
65+
the start. The replacement preserves valid JSON and does not touch
66+
`opencode.jsonc`.
67+
6. Once all staging succeeds, the function atomically moves the staged files
68+
into place, updates the eza symlink, reloads tmux, then writes the selected
69+
canonical profile to `~/.config/colorscheme`.
70+
7. The function prints a concise completion message that tmux was reloaded and
71+
that OpenCode and other affected applications need restarting.
72+
73+
## Failure behaviour
74+
75+
- `set -x` is removed so normal switching does not emit command traces.
76+
- Quoted variable expansions are used for paths and values.
77+
- A failed validation or failed staging operation leaves the existing live
78+
configuration untouched.
79+
- A tmux reload failure is reported after files are updated; it does not undo
80+
the selected configuration because the next tmux startup will read it.
81+
- The design does not promise rollback for a filesystem failure during the final
82+
sequence of atomic moves, but it minimizes that window by completing all
83+
fallible generation before altering live files.
84+
85+
## Verification
86+
87+
- Add or update a focused shell test covering every profile's OpenCode alias,
88+
including `catppuccin_mocha -> catppuccin` and `onedark -> one-dark`.
89+
- Test that the TUI configuration, rather than `opencode.jsonc`, receives the
90+
OpenCode theme update.
91+
- Test that missing required config or theme assets stop before any target file
92+
changes.
93+
- Run `zsh -n conf/zsh/fun/colorscheme.zsh` and `git diff --check`.
94+
- Manually run `cs`, select a profile, restart OpenCode, and confirm its TUI
95+
theme matches the selected profile.

0 commit comments

Comments
 (0)