opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(tui): system-like custom themes

Open nihil2501 opened this issue 1 day ago • 2 comments

Issues

  • Closes #6322
  • Closes #4236
    • Something akin to this feature is discussed within the comments

Feature

tui-theme

Custom themes can now reference the system theme that is generated from the user's terminal color palette by using "system" as a color value:

{
  "theme": {
    "background": "system",
    "foreground": "system",
    "primary": "#ff5500"
  }
}

Performance optimization

The theme context now readies 10x faster in the by-far most common case (using one of the default themes). The speedup is due to not waiting for resources to load that are irrelevant for the requested theme. Timed using this patch that calls console.time inside createSimpleContext.

After = 3.558ms

...
[17:05:25] [LOG] '%s: %s' 'context:Theme' '3.558ms'
...

Before = 31.264ms

...
[17:04:19] [LOG] '%s: %s' 'context:Theme' '31.264ms'
...

More details

Key behaviors

  • Custom theme loading and system palette detection each modeled w/ SolidJS's createResource
  • These in turn are accessed in SolidJS's createMemo returning (requested theme, resource loading status)
    • Considers only the relevant resource loading statuses for the given requested theme
    • Drives the reactivity into theme resolution
  • Somewhat conservative & simplistic design choices

Miscellany

  • Warning toasts on errored (this functionality could easily be removed)
  • System theme now responds to Toggle appearance
  • Theme picker list now updates on reload

Commits

Three atomic commits build up to this feature:

  1. fix(tui): system theme light & dark variants
  2. refactor(tui): theme switching & loading reactivity
  3. feat(tui): system-like custom themes

Notes

  • This can be split into 3 sequential PRs if preferred, one per atomic commit above
  • The first 2 commits might be valuable without adding this feature in the 3rd commit
  • The performance optimization is in the 2nd, refactor commit

nihil2501 avatar Jan 18 '26 03:01 nihil2501