From e830e4dfda63c3804a1ddb8b4b542353948e1be9 Mon Sep 17 00:00:00 2001 From: MDietermann Date: Tue, 14 Apr 2026 09:58:04 +0200 Subject: [PATCH] feat(tui): add NvChadTheme field and ThemeByID helper --- internal/tui/state.go | 30 +++++++++++++++++++++--------- internal/tui/state_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/internal/tui/state.go b/internal/tui/state.go index 5120f51..63b5965 100644 --- a/internal/tui/state.go +++ b/internal/tui/state.go @@ -7,21 +7,33 @@ import ( "github.com/MDietermann/ArduinoArchSetup/internal/module" ) -// Theme is a named colorscheme presented in the wizard. Plan 3 wires these -// names to actual theme modules; for now they are display-only strings. +// Theme is a named colorscheme presented in the wizard. Each entry carries +// per-tool theme names; Plan 3b uses NvChadTheme, later plans add more. type Theme struct { - ID string - Name string + 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"}, - {ID: "catppuccin", Name: "Catppuccin Mocha"}, - {ID: "tokyonight", Name: "Tokyo Night"}, - {ID: "nord", Name: "Nord"}, - {ID: "dracula", Name: "Dracula"}, + {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 } // ModuleChoice is one row in the module selector. diff --git a/internal/tui/state_test.go b/internal/tui/state_test.go index 192272d..90d5dc7 100644 --- a/internal/tui/state_test.go +++ b/internal/tui/state_test.go @@ -70,3 +70,31 @@ func TestSelectedIDsOnlyReturnsChecked(t *testing.T) { t.Fatalf("got %v", got) } } + +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") + } +}