vcom/internal/tui/theme_select.go
vrubelroman 40b8722d58 feat(tui): App skeleton with mode machine, async navigation and effects (6.1.5)
The new UI's root model: Screen x viewer focus x native selection x
filter edit x modal stack, one inputOwner, keys resolved through the
registry, an action table that features extend from register_*.go.
Directory reads and previews run in Cmds with tickets: Update never
blocks (N-P1-1), stale results are dropped (U-P1-13), failed navigation
keeps the panel and a vanished directory climbs up (U-P1-8). q closes
layers before asking to quit (U-P1-16), PgDn pages (U-P1-6), the theme
list previews live and saves with config.SetKey. Mouse mode is
reconciled after every Update; View only reads state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 09:11:39 +03:00

54 lines
1.3 KiB
Go

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))
}