feat(tui): add NvChadTheme field and ThemeByID helper
This commit is contained in:
@@ -7,21 +7,33 @@ import (
|
|||||||
"github.com/MDietermann/ArduinoArchSetup/internal/module"
|
"github.com/MDietermann/ArduinoArchSetup/internal/module"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Theme is a named colorscheme presented in the wizard. Plan 3 wires these
|
// Theme is a named colorscheme presented in the wizard. Each entry carries
|
||||||
// names to actual theme modules; for now they are display-only strings.
|
// per-tool theme names; Plan 3b uses NvChadTheme, later plans add more.
|
||||||
type Theme struct {
|
type Theme struct {
|
||||||
ID string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
|
NvChadTheme string
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuiltinThemes is the fixed list the wizard shows. Keep in sync with the
|
// BuiltinThemes is the fixed list the wizard shows. Keep in sync with the
|
||||||
// themes shipped by Plan 3's theme module.
|
// themes shipped by Plan 3's theme module.
|
||||||
var BuiltinThemes = []Theme{
|
var BuiltinThemes = []Theme{
|
||||||
{ID: "gruvbox", Name: "Gruvbox Dark"},
|
{ID: "gruvbox", Name: "Gruvbox Dark", NvChadTheme: "gruvbox"},
|
||||||
{ID: "catppuccin", Name: "Catppuccin Mocha"},
|
{ID: "catppuccin", Name: "Catppuccin Mocha", NvChadTheme: "catppuccin"},
|
||||||
{ID: "tokyonight", Name: "Tokyo Night"},
|
{ID: "tokyonight", Name: "Tokyo Night", NvChadTheme: "tokyonight"},
|
||||||
{ID: "nord", Name: "Nord"},
|
{ID: "nord", Name: "Nord", NvChadTheme: "nord"},
|
||||||
{ID: "dracula", Name: "Dracula"},
|
{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.
|
// ModuleChoice is one row in the module selector.
|
||||||
|
|||||||
@@ -70,3 +70,31 @@ func TestSelectedIDsOnlyReturnsChecked(t *testing.T) {
|
|||||||
t.Fatalf("got %v", got)
|
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