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:
@@ -13,11 +13,17 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/config"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/neovim"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/platform"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// ChadrcWriter is the hook used by Apply to rewrite NvChad's chadrc.lua
|
||||
// after a theme change. The neovim module registers its WriteChadrc here
|
||||
// via an init() function to avoid a theming→neovim import cycle (neovim
|
||||
// now imports theming to look up the NvChad theme name). If nil, Apply
|
||||
// skips the chadrc update silently.
|
||||
var ChadrcWriter func(nvChadThemeName string) error
|
||||
|
||||
//go:embed assets
|
||||
var assetsFS embed.FS
|
||||
|
||||
@@ -146,8 +152,10 @@ func Apply(cfg config.Config, themeID string) error {
|
||||
return fmt.Errorf("update overlay: %w", err)
|
||||
}
|
||||
|
||||
if err := neovim.WriteChadrc(th.NvChadTheme); err != nil {
|
||||
return fmt.Errorf("update chadrc: %w", err)
|
||||
if ChadrcWriter != nil {
|
||||
if err := ChadrcWriter(th.NvChadTheme); err != nil {
|
||||
return fmt.Errorf("update chadrc: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Clear NvChad's base46 theme cache so the new theme activates on next
|
||||
|
||||
@@ -129,6 +129,17 @@ func TestApplyRewritesChadrcIfPresent(t *testing.T) {
|
||||
[]byte(`M.base46 = { theme = "onedark" }`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// The real ChadrcWriter lives in the neovim package, which cannot be
|
||||
// imported here without creating an import cycle (neovim→theming).
|
||||
// Stub it with a minimal writer that covers what the test asserts.
|
||||
prev := ChadrcWriter
|
||||
t.Cleanup(func() { ChadrcWriter = prev })
|
||||
ChadrcWriter = func(name string) error {
|
||||
return os.WriteFile(filepath.Join(nvimCfg, "chadrc.lua"),
|
||||
[]byte(`theme = "`+name+`"`), 0o644)
|
||||
}
|
||||
|
||||
if err := Apply(config.Config{}, "gruvbox"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user