From bc8c633b02371517a825b56f4f7b1baeb0a0659d Mon Sep 17 00:00:00 2001 From: Dolev Hadar Date: Sat, 9 Nov 2024 21:51:19 +0200 Subject: [PATCH] fix: default config parsing --- config/parser.go | 25 +++++++++---------------- ui/theme/theme.go | 47 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 24 deletions(-) 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 }