Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default config parsing #480

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}