refactor: retire tui.BuiltinThemes in favor of theming.List
Make internal/theming.List the single source of truth for themes:
- Drop tui.BuiltinThemes, tui.ThemeByID, and the NvChadTheme field on
tui.Theme. tui.Theme is now a thin {ID, Name} display value.
- Wizard populates its dropdown from theming.List() and uses
DisplayName for the label.
- neovim.resolvedTheme uses theming.Get (with theming.List()[0] as a
fallback) instead of a caller-supplied []tui.Theme slice.
- neovim.New signature loses the themes []tui.Theme parameter; update
cmd/archduino/main.go and all neovim tests to match.
Break the resulting neovim→theming import cycle (theming previously
imported neovim for WriteChadrc) by inverting the dependency:
theming exposes a ChadrcWriter function hook, and neovim registers
its WriteChadrc into it via package init. The theming test stubs
ChadrcWriter directly to exercise the chadrc-rewrite branch without
pulling neovim in and re-creating the cycle.
Delete the now-obsolete TestBuiltinThemesCarryNvChadName / TestThemeByID*
tests in internal/tui/state_test.go — their coverage lives in the
theming package's own tests.
This commit is contained in:
@@ -5,35 +5,15 @@ import (
|
||||
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/config"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/module"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/theming"
|
||||
)
|
||||
|
||||
// Theme is a named colorscheme presented in the wizard. Each entry carries
|
||||
// per-tool theme names; Plan 3b uses NvChadTheme, later plans add more.
|
||||
// Theme is a named colorscheme presented in the wizard. It is a thin
|
||||
// display value for the dropdown; the authoritative theme catalogue lives
|
||||
// in the theming package (theming.List / theming.Get).
|
||||
type Theme struct {
|
||||
ID string
|
||||
Name string
|
||||
NvChadTheme string
|
||||
}
|
||||
|
||||
// BuiltinThemes is the fixed list the wizard shows. Keep in sync with the
|
||||
// themes shipped by Plan 3's theme module.
|
||||
var BuiltinThemes = []Theme{
|
||||
{ID: "gruvbox", Name: "Gruvbox Dark", NvChadTheme: "gruvbox"},
|
||||
{ID: "catppuccin", Name: "Catppuccin Mocha", NvChadTheme: "catppuccin"},
|
||||
{ID: "tokyonight", Name: "Tokyo Night", NvChadTheme: "tokyonight"},
|
||||
{ID: "nord", Name: "Nord", NvChadTheme: "nord"},
|
||||
{ID: "dracula", Name: "Dracula", NvChadTheme: "dracula"},
|
||||
}
|
||||
|
||||
// ThemeByID returns the Theme with the given ID. The bool is false when no
|
||||
// match is found; callers decide whether to fall back or error.
|
||||
func ThemeByID(themes []Theme, id string) (Theme, bool) {
|
||||
for _, t := range themes {
|
||||
if t.ID == id {
|
||||
return t, true
|
||||
}
|
||||
}
|
||||
return Theme{}, false
|
||||
ID string
|
||||
Name string
|
||||
}
|
||||
|
||||
// ModuleChoice is one row in the module selector.
|
||||
@@ -74,7 +54,10 @@ func NewWizardState(cfg config.Config, reg *module.Registry) WizardState {
|
||||
}
|
||||
sort.Slice(choices, func(i, j int) bool { return choices[i].ID < choices[j].ID })
|
||||
|
||||
theme := BuiltinThemes[0].ID
|
||||
var theme string
|
||||
if list := theming.List(); len(list) > 0 {
|
||||
theme = list[0].ID
|
||||
}
|
||||
if override, ok := cfg.ThemeOverrides["__active"]; ok && override != "" {
|
||||
theme = override
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/config"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/module"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/theming"
|
||||
)
|
||||
|
||||
type fakeModule struct{ id, name, desc string }
|
||||
@@ -34,7 +35,7 @@ func TestNewWizardStatePreTicksAllByDefault(t *testing.T) {
|
||||
t.Errorf("%s not selected", m.ID)
|
||||
}
|
||||
}
|
||||
if s.ThemeID != BuiltinThemes[0].ID {
|
||||
if s.ThemeID != theming.List()[0].ID {
|
||||
t.Errorf("theme = %q", s.ThemeID)
|
||||
}
|
||||
}
|
||||
@@ -71,30 +72,3 @@ func TestSelectedIDsOnlyReturnsChecked(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuiltinThemesCarryNvChadName(t *testing.T) {
|
||||
for _, th := range BuiltinThemes {
|
||||
if th.NvChadTheme == "" {
|
||||
t.Errorf("theme %q has empty NvChadTheme", th.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestThemeByIDReturnsMatch(t *testing.T) {
|
||||
got, ok := ThemeByID(BuiltinThemes, "dracula")
|
||||
if !ok {
|
||||
t.Fatal("dracula should exist")
|
||||
}
|
||||
if got.ID != "dracula" {
|
||||
t.Fatalf("got id=%q", got.ID)
|
||||
}
|
||||
if got.NvChadTheme == "" {
|
||||
t.Fatal("NvChadTheme empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestThemeByIDFallsBackWhenUnknown(t *testing.T) {
|
||||
_, ok := ThemeByID(BuiltinThemes, "does-not-exist")
|
||||
if ok {
|
||||
t.Fatal("unknown id should report ok=false")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/charmbracelet/huh"
|
||||
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/module"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/theming"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/tui"
|
||||
)
|
||||
|
||||
@@ -23,9 +24,10 @@ func Run(ctx context.Context, reg *module.Registry, initial tui.WizardState) (tu
|
||||
return s, false, nil
|
||||
}
|
||||
|
||||
themeOptions := make([]huh.Option[string], 0, len(tui.BuiltinThemes))
|
||||
for _, t := range tui.BuiltinThemes {
|
||||
themeOptions = append(themeOptions, huh.NewOption(t.Name, t.ID))
|
||||
themes := theming.List()
|
||||
themeOptions := make([]huh.Option[string], 0, len(themes))
|
||||
for _, t := range themes {
|
||||
themeOptions = append(themeOptions, huh.NewOption(t.DisplayName, t.ID))
|
||||
}
|
||||
|
||||
moduleOptions := make([]huh.Option[string], 0, len(s.Modules))
|
||||
|
||||
Reference in New Issue
Block a user