feat(tui): add NvChadTheme field and ThemeByID helper
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user