Skip to content

Commit

Permalink
fix: default config parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr committed Nov 9, 2024
1 parent 5ec0201 commit b24c601
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 24 deletions.
25 changes: 9 additions & 16 deletions config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down
47 changes: 39 additions & 8 deletions ui/theme/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package theme

import (
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"

"github.com/dlvhdr/gh-dash/v4/config"
)
Expand Down Expand Up @@ -35,33 +36,63 @@ 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)}
}

if cfg.Theme.Colors != nil {
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
}

0 comments on commit b24c601

Please sign in to comment.