feat(theming): integrate NvChad chadrc rewrite into Apply

This commit is contained in:
MDietermann
2026-04-14 13:14:47 +02:00
parent 4fa580f226
commit 770bdcf3a2
4 changed files with 109 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ 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"
)
@@ -144,6 +145,15 @@ func Apply(cfg config.Config, themeID string) error {
if err := updateOverlayActive(th.ID); err != nil {
return fmt.Errorf("update overlay: %w", err)
}
if err := neovim.WriteChadrc(th.NvChadTheme); err != nil {
return fmt.Errorf("update chadrc: %w", err)
}
// Clear NvChad's base46 theme cache so the new theme activates on next
// nvim launch. Errors ignored — the cache may not exist.
_ = os.RemoveAll(filepath.Join(home, ".cache", "nvim", "base46"))
_ = os.RemoveAll(filepath.Join(home, ".local", "share", "nvim", "lazy", "base46", "lua", "base46", "themes"))
return nil
}

View File

@@ -117,3 +117,34 @@ func TestApplyPreservesOtherOverlayKeys(t *testing.T) {
t.Fatalf("active theme missing after preserve: %s", data)
}
}
func TestApplyRewritesChadrcIfPresent(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
nvimCfg := filepath.Join(home, ".config", "nvim", "lua")
if err := os.MkdirAll(nvimCfg, 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(nvimCfg, "chadrc.lua"),
[]byte(`M.base46 = { theme = "onedark" }`), 0o644); err != nil {
t.Fatal(err)
}
if err := Apply(config.Config{}, "gruvbox"); err != nil {
t.Fatal(err)
}
data, _ := os.ReadFile(filepath.Join(nvimCfg, "chadrc.lua"))
if !strings.Contains(string(data), `theme = "gruvbox"`) {
t.Fatalf("chadrc not rewritten: %s", data)
}
if strings.Contains(string(data), `theme = "onedark"`) {
t.Fatalf("old theme still present: %s", data)
}
}
func TestApplyNoChadrcIsFine(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
if err := Apply(config.Config{}, "gruvbox"); err != nil {
t.Fatal(err)
}
}