mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-04-20 16:40:29 +00:00
29 lines
827 B
Go
29 lines
827 B
Go
package appview
|
|
|
|
import "fmt"
|
|
|
|
// themeRegistry maps theme names to their BrandingOverrides constructors.
|
|
var themeRegistry = make(map[string]func() *BrandingOverrides)
|
|
|
|
// RegisterTheme registers a named theme. Call from init() in theme packages.
|
|
func RegisterTheme(name string, fn func() *BrandingOverrides) {
|
|
if _, exists := themeRegistry[name]; exists {
|
|
panic(fmt.Sprintf("theme %q already registered", name))
|
|
}
|
|
themeRegistry[name] = fn
|
|
}
|
|
|
|
// LookupTheme returns BrandingOverrides for a registered theme name.
|
|
// Returns nil for empty name (default branding). Returns an error for
|
|
// unknown theme names.
|
|
func LookupTheme(name string) (*BrandingOverrides, error) {
|
|
if name == "" {
|
|
return nil, nil
|
|
}
|
|
fn, ok := themeRegistry[name]
|
|
if !ok {
|
|
return nil, fmt.Errorf("unknown theme %q", name)
|
|
}
|
|
return fn(), nil
|
|
}
|