diff --git a/config/parser.go b/config/parser.go index 276e93b0..4b46b19e 100644 --- a/config/parser.go +++ b/config/parser.go @@ -143,22 +143,22 @@ type HexColor string type ColorThemeText struct { Primary HexColor `yaml:"primary" validate:"omitempty,hexcolor"` - Secondary HexColor `yaml:"secondary" validate:"hexcolor"` - Inverted HexColor `yaml:"inverted" validate:"hexcolor"` - Faint HexColor `yaml:"faint" validate:"hexcolor"` - Warning HexColor `yaml:"warning" validate:"hexcolor"` - Success HexColor `yaml:"success" validate:"hexcolor"` + Secondary HexColor `yaml:"secondary" validate:"omitempty,hexcolor"` + Inverted HexColor `yaml:"inverted" validate:"omitempty,hexcolor"` + Faint HexColor `yaml:"faint" validate:"omitempty,hexcolor"` + Warning HexColor `yaml:"warning" validate:"omitempty,hexcolor"` + Success HexColor `yaml:"success" validate:"omitempty,hexcolor"` Error HexColor `yaml:"error" validate:"omitempty,hexcolor"` } type ColorThemeBorder struct { - Primary HexColor `yaml:"primary" validate:"hexcolor"` - Secondary HexColor `yaml:"secondary" validate:"hexcolor"` - Faint HexColor `yaml:"faint" validate:"hexcolor"` + Primary HexColor `yaml:"primary" validate:"omitempty,hexcolor"` + Secondary HexColor `yaml:"secondary" validate:"omitempty,hexcolor"` + Faint HexColor `yaml:"faint" validate:"omitempty,hexcolor"` } type ColorThemeBackground struct { - Selected HexColor `yaml:"selected" validate:"hexcolor"` + Selected HexColor `yaml:"selected" validate:"omitempty,hexcolor"` } type ColorTheme struct { @@ -296,13 +296,6 @@ func (parser ConfigParser) getDefaultConfig() Config { }, RepoPaths: map[string]string{}, Theme: &ThemeConfig{ - Colors: &ColorThemeConfig{ - Inline: ColorTheme{ - Text: ColorThemeText{ - Error: "#F7768E", - }, - }, - }, Ui: UIThemeConfig{ SectionsShowCount: true, Table: TableUIThemeConfig{ diff --git a/ui/theme/theme.go b/ui/theme/theme.go index 0c9078e6..0af8c237 100644 --- a/ui/theme/theme.go +++ b/ui/theme/theme.go @@ -2,6 +2,7 @@ package theme import ( "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/log" "github.com/dlvhdr/gh-dash/v4/config" ) @@ -35,7 +36,10 @@ var DefaultTheme = &Theme{ } func ParseTheme(cfg *config.Config) Theme { - _shimHex := func(hex config.HexColor) lipgloss.AdaptiveColor { + _shimHex := func(hex config.HexColor, fallback lipgloss.AdaptiveColor) lipgloss.AdaptiveColor { + if hex == "" { + return fallback + } return lipgloss.AdaptiveColor{Light: string(hex), Dark: string(hex)} } @@ -43,25 +47,52 @@ func ParseTheme(cfg *config.Config) Theme { DefaultTheme = &Theme{ SelectedBackground: _shimHex( cfg.Theme.Colors.Inline.Background.Selected, + DefaultTheme.SelectedBackground, ), PrimaryBorder: _shimHex( cfg.Theme.Colors.Inline.Border.Primary, + DefaultTheme.PrimaryBorder, + ), + FaintBorder: _shimHex( + cfg.Theme.Colors.Inline.Border.Faint, + DefaultTheme.FaintBorder, ), - FaintBorder: _shimHex(cfg.Theme.Colors.Inline.Border.Faint), SecondaryBorder: _shimHex( cfg.Theme.Colors.Inline.Border.Secondary, + DefaultTheme.SecondaryBorder, + ), + FaintText: _shimHex( + cfg.Theme.Colors.Inline.Text.Faint, + DefaultTheme.FaintText, + ), + PrimaryText: _shimHex( + cfg.Theme.Colors.Inline.Text.Primary, + DefaultTheme.PrimaryText, ), - FaintText: _shimHex(cfg.Theme.Colors.Inline.Text.Faint), - PrimaryText: _shimHex(cfg.Theme.Colors.Inline.Text.Primary), SecondaryText: _shimHex( cfg.Theme.Colors.Inline.Text.Secondary, + DefaultTheme.SecondaryText, + ), + InvertedText: _shimHex( + cfg.Theme.Colors.Inline.Text.Inverted, + DefaultTheme.InvertedText, + ), + SuccessText: _shimHex( + cfg.Theme.Colors.Inline.Text.Success, + DefaultTheme.SuccessText, + ), + WarningText: _shimHex( + cfg.Theme.Colors.Inline.Text.Warning, + DefaultTheme.WarningText, + ), + ErrorText: _shimHex( + cfg.Theme.Colors.Inline.Text.Error, + DefaultTheme.ErrorText, ), - InvertedText: _shimHex(cfg.Theme.Colors.Inline.Text.Inverted), - SuccessText: _shimHex(cfg.Theme.Colors.Inline.Text.Success), - WarningText: _shimHex(cfg.Theme.Colors.Inline.Text.Warning), - ErrorText: _shimHex(cfg.Theme.Colors.Inline.Text.Error), } } + log.Debug("Parsing theme", "config", cfg.Theme.Colors, "theme", DefaultTheme) + return *DefaultTheme }