xonecas.io
62159
Sy

symb / commit cb209ab

feat: use theme from config

xonecas2026-02-19 cb209ab144a41c2db9d3f34c1346d76054dccd55 parent edaf17d

8 files changed

cmd/symb/main.go+1−1
@@ -135,7 +135,7 @@ func main() {
135135 }
136136
137137 p := tea.NewProgram(
138- tui.New(prov, svc.proxy, tools, providerCfg.Model, svc.webCache, sessionID, tsIndex, svc.deltaTracker, svc.fileTracker, providerName, svc.scratchpad, resumeHistory, registry, providerOpts),
138+ tui.New(prov, svc.proxy, tools, providerCfg.Model, svc.webCache, sessionID, tsIndex, svc.deltaTracker, svc.fileTracker, providerName, svc.scratchpad, resumeHistory, registry, providerOpts, cfg.UI.SyntaxThemeOrDefault()),
139139 tea.WithFilter(tui.MouseEventFilter),
140140 )
141141 svc.lspManager.SetCallback(func(absPath string, lines map[int]int) {
config.example.toml+30−1
@@ -12,7 +12,36 @@ model = "qwen3:8b"
1212 model = "glm-5"
1313
1414 [ui]
15-# TODO
15+# syntax_theme sets the Chroma syntax highlighting theme used across the TUI.
16+# UI chrome colors (grayscale ramp, accent, error) are derived from the theme
17+# via highlight.ThemePalette — theme authors only need to define the Chroma XML.
18+#
19+# Only themes with complete token coverage (60+ entries, 10+ Generic tokens)
20+# are listed. Incomplete themes will render markdown headings, bold, italic,
21+# and diff hunks without differentiation.
22+#
23+# Dark themes:
24+# tokyonight-night #1a1b26 81 entries
25+# tokyonight-storm #1a1b26 81 entries
26+# tokyonight-moon #222436 81 entries
27+# catppuccin-mocha #1e1e2e 81 entries
28+# catppuccin-macchiato #24273a 81 entries
29+# catppuccin-frappe #303446 81 entries
30+# aura-theme-dark #15141b 84 entries
31+# aura-theme-dark-soft #15141b 84 entries
32+# dracula #282a36 72 entries
33+# base16-snazzy #282a36 72 entries
34+# vulcan #282c34 72 entries
35+# doom-one2 #282c34 62 entries
36+# github-dark #0d1117 43 entries
37+# ashen #121212 66 entries
38+# average #000000 72 entries
39+#
40+# Light themes:
41+# tokyonight-day #e1e2e7 81 entries
42+# catppuccin-latte #eff1f5 81 entries
43+#
44+syntax_theme = "vulcan"
1645
1746 [cache]
1847 ttl_hours = 24
internal/config/config.go+17−0
@@ -17,6 +17,23 @@ type Config struct {
1717 Providers map[string]ProviderConfig `toml:"providers"`
1818 MCP MCPConfig `toml:"mcp"`
1919 Cache CacheConfig `toml:"cache"`
20+ UI UIConfig `toml:"ui"`
21+}
22+
23+// UIConfig holds user-interface settings.
24+type UIConfig struct {
25+ // SyntaxTheme is the Chroma syntax highlighting theme used across the TUI.
26+ // UI chrome colors are derived from this theme via highlight.ThemePalette.
27+ // Defaults to "vulcan" if unset.
28+ SyntaxTheme string `toml:"syntax_theme"`
29+}
30+
31+// SyntaxThemeOrDefault returns the configured syntax theme or "vulcan" if unset.
32+func (u UIConfig) SyntaxThemeOrDefault() string {
33+ if u.SyntaxTheme == "" {
34+ return "vulcan"
35+ }
36+ return u.SyntaxTheme
2037 }
2138
2239 // CacheConfig holds web cache settings.
internal/constants/constants.go+0−31
@@ -1,31 +0,0 @@
1-package constants
2-
3-// SyntaxTheme is the Chroma syntax highlighting theme used across the TUI.
4-// UI chrome colors (grayscale ramp, accent, error) are derived from the theme
5-// via highlight.ThemePalette — theme authors only need to define the Chroma XML.
6-//
7-// Only themes with complete token coverage (60+ entries, 10+ Generic tokens)
8-// are listed. Incomplete themes will render markdown headings, bold, italic,
9-// and diff hunks without differentiation.
10-//
11-// Dark themes:
12-// - tokyonight-night #1a1b26 81 entries
13-// - tokyonight-storm #1a1b26 81 entries
14-// - tokyonight-moon #222436 81 entries
15-// - catppuccin-mocha #1e1e2e 81 entries
16-// - catppuccin-macchiato #24273a 81 entries
17-// - catppuccin-frappe #303446 81 entries
18-// - aura-theme-dark #15141b 84 entries
19-// - aura-theme-dark-soft #15141b 84 entries
20-// - dracula #282a36 72 entries
21-// - base16-snazzy #282a36 72 entries
22-// - vulcan #282c34 72 entries
23-// - doom-one2 #282c34 62 entries
24-// - github-dark #0d1117 43 entries
25-// - ashen #121212 66 entries
26-// - average #000000 72 entries
27-//
28-// Light themes:
29-// - tokyonight-day #e1e2e7 81 entries
30-// - catppuccin-latte #eff1f5 81 entries
31-const SyntaxTheme = "vulcan"
internal/tui/conv.go+1−2
@@ -5,7 +5,6 @@ import (
55 "strings"
66
77 "charm.land/lipgloss/v2"
8- "github.com/xonecas/symb/internal/constants"
98 "github.com/xonecas/symb/internal/highlight"
109 "github.com/xonecas/symb/internal/provider"
1110 )
@@ -22,7 +21,7 @@ func (m Model) convWidth() int { return m.layout.conv.Dx() }
2221 // (fenced code blocks, block quotes, etc.) maintain correct state.
2322 // Rendering cost is bounded by the frame-loop tick (~16ms).
2423 func highlightMarkdown(text string, fallback lipgloss.Style) []string {
25- hl := highlight.Highlight(text, "markdown", constants.SyntaxTheme, palette.Bg)
24+ hl := highlight.Highlight(text, "markdown", syntaxThemeName, palette.Bg)
2625 if hl == text {
2726 // Chroma produced no highlighting; apply fallback per line.
2827 raw := strings.Split(text, "\n")
internal/tui/golden_test.go+1−1
@@ -27,7 +27,7 @@ func TestLayout(t *testing.T) {
2727
2828 for _, tt := range tests {
2929 t.Run(tt.name, func(t *testing.T) {
30- m := New(nil, nil, nil, "test-model", nil, "test-session", nil, nil, nil, "test-provider", nil, nil, nil, provider.Options{})
30+ m := New(nil, nil, nil, "test-model", nil, "test-session", nil, nil, nil, "test-provider", nil, nil, nil, provider.Options{}, "vulcan")
3131 updated, _ := m.Update(tea.WindowSizeMsg{Width: tt.width, Height: tt.height})
3232 m = updated.(Model)
3333
internal/tui/styles.go+34−13
@@ -1,30 +1,51 @@
11 package tui
22
33 import (
4+ "image/color"
5+
46 "charm.land/lipgloss/v2"
5- "github.com/xonecas/symb/internal/constants"
67 "github.com/xonecas/symb/internal/highlight"
78 )
89
9-// palette is computed once from the Chroma theme at init time.
10-var palette = highlight.ThemePalette(constants.SyntaxTheme)
10+// palette and syntaxThemeName are computed once when the TUI is initialised.
11+var (
12+ palette highlight.Palette
13+ syntaxThemeName string
14+)
1115
1216 // Semantic color palette — derived from the active Chroma syntax theme.
1317 // Grayscale ramp is a linear interpolation from theme bg to fg.
1418 // Accent is the most saturated token color; error is lerped from the theme Error token.
1519 var (
16- ColorHighlight = lipgloss.Color(palette.Accent)
17- ColorBg = lipgloss.Color(palette.Bg)
18- ColorFg = lipgloss.Color(palette.Fg)
19- ColorMuted = lipgloss.Color(palette.Muted)
20- ColorDim = lipgloss.Color(palette.Dim)
21- ColorBorder = lipgloss.Color(palette.Border)
22- ColorSurface = lipgloss.Color(palette.Accent)
23- ColorError = lipgloss.Color(palette.Error)
24- ColorWarning = lipgloss.Color(palette.Error) // same source, context differentiates
25- ColorLinkBg = lipgloss.Color(palette.LinkBg)
20+ ColorHighlight color.Color
21+ ColorBg color.Color
22+ ColorFg color.Color
23+ ColorMuted color.Color
24+ ColorDim color.Color
25+ ColorBorder color.Color
26+ ColorSurface color.Color
27+ ColorError color.Color
28+ ColorWarning color.Color
29+ ColorLinkBg color.Color
2630 )
2731
32+// initTheme sets the palette and color vars from the given Chroma theme name.
33+// Must be called before DefaultStyles or any Color* variable is used.
34+func initTheme(syntaxTheme string) {
35+ syntaxThemeName = syntaxTheme
36+ palette = highlight.ThemePalette(syntaxTheme)
37+ ColorHighlight = lipgloss.Color(palette.Accent)
38+ ColorBg = lipgloss.Color(palette.Bg)
39+ ColorFg = lipgloss.Color(palette.Fg)
40+ ColorMuted = lipgloss.Color(palette.Muted)
41+ ColorDim = lipgloss.Color(palette.Dim)
42+ ColorBorder = lipgloss.Color(palette.Border)
43+ ColorSurface = lipgloss.Color(palette.Accent)
44+ ColorError = lipgloss.Color(palette.Error)
45+ ColorWarning = lipgloss.Color(palette.Error) // same source, context differentiates
46+ ColorLinkBg = lipgloss.Color(palette.LinkBg)
47+}
48+
2849 // Styles holds all pre-built lipgloss styles used across the TUI.
2950 // Constructed once, stored in Model, avoids repeated allocations.
3051 type Styles struct {
internal/tui/tui.go+4−4
@@ -8,7 +8,6 @@ import (
88
99 tea "charm.land/bubbletea/v2"
1010 "charm.land/lipgloss/v2"
11- "github.com/xonecas/symb/internal/constants"
1211 "github.com/xonecas/symb/internal/delta"
1312 "github.com/xonecas/symb/internal/filesearch"
1413 "github.com/xonecas/symb/internal/llm"
@@ -289,7 +288,8 @@ type Model struct {
289288 // New creates a new TUI model.
290289 // If resumeHistory is non-nil, the session is being resumed and messages are
291290 // loaded from the database instead of creating a fresh system prompt.
292-func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID string, db *store.Cache, sessionID string, idx *treesitter.Index, dt *delta.Tracker, ft FileReadResetter, providerConfigName string, pad llm.ScratchpadReader, resumeHistory []provider.Message, registry *provider.Registry, providerOpts provider.Options) Model {
291+func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID string, db *store.Cache, sessionID string, idx *treesitter.Index, dt *delta.Tracker, ft FileReadResetter, providerConfigName string, pad llm.ScratchpadReader, resumeHistory []provider.Message, registry *provider.Registry, providerOpts provider.Options, syntaxTheme string) Model {
292+ initTheme(syntaxTheme)
293293 sty := DefaultStyles()
294294 cursorStyle := lipgloss.NewStyle().Foreground(ColorHighlight)
295295
@@ -299,7 +299,7 @@ func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID str
299299 ed.ShowLineNumbers = true
300300 ed.ReadOnly = false
301301 ed.Language = "markdown"
302- ed.SyntaxTheme = constants.SyntaxTheme
302+ ed.SyntaxTheme = syntaxTheme
303303 ed.CursorStyle = cursorStyle
304304 ed.SelectionStyle = selStyle
305305 ed.LineNumStyle = lipgloss.NewStyle().Foreground(ColorBorder)
@@ -314,7 +314,7 @@ func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID str
314314 ai.Placeholder = "Ask anything... (CTRL+h for keybinds)"
315315 ai.SubmitOnEnter = true
316316 ai.Language = "markdown"
317- ai.SyntaxTheme = constants.SyntaxTheme
317+ ai.SyntaxTheme = syntaxTheme
318318 ai.CursorStyle = cursorStyle
319319 ai.SelectionStyle = selStyle
320320 ai.PlaceholderSty = lipgloss.NewStyle().Foreground(ColorDim).Background(ColorBg)