package tui import ( "fmt" tea "github.com/charmbracelet/bubbletea" "vcom/internal/theme" "vcom/internal/tui/modal" "vcom/internal/tui/notify" ) type themeSavedMsg struct { Theme string Path string Err error } // openThemeSelect is "t": a list with live preview; Enter keeps and saves // the theme with config.SetKey (comments kept, design ยง9.2), Esc reverts. func (a *App) openThemeSelect() tea.Cmd { orig := a.theme var items []modal.Item for _, n := range theme.Names() { items = append(items, modal.Item{Label: n, Value: n}) } l := modal.NewList("Theme", items, orig) l.OnMove = func(it modal.Item) tea.Cmd { a.setTheme(it.Value.(string)) // runs in Update: no I/O return nil } a.openModal(l, func(o modal.Outcome) tea.Cmd { if o.Cancelled { a.setTheme(orig) return nil } name := o.Value.(string) a.setTheme(name) a.deps.Config.UI.Theme = name set, path := a.deps.SetConfigKey, a.deps.ConfigPath return func() tea.Msg { p, err := set(path, "ui", "theme", name) return themeSavedMsg{Theme: name, Path: p, Err: err} } }) return nil } func (a *App) onThemeSaved(m themeSavedMsg) tea.Cmd { if m.Err != nil { return a.notify(notify.Error, fmt.Sprintf("Theme %s not saved: %v", m.Theme, m.Err)) } return a.notify(notify.Success, fmt.Sprintf("Theme %s saved to %s", m.Theme, m.Path)) }