diff --git a/internal/config/config.toml b/internal/config/config.toml index f5b810c..db4fba2 100644 --- a/internal/config/config.toml +++ b/internal/config/config.toml @@ -94,19 +94,17 @@ cancel = "Esc" background_color = "default" [theme.title] -# Title color of non-focused widgets -color = "default" -# Title color of the focused widget -active_color = "green" alignment = "left" +style = { foreground = "default" } +active_style = { foreground = "green" } [theme.border] enabled = true # [top, bottom, left, right] padding = [0, 0, 1, 1] set = "round" -color = "default" -active_color = "green" +style = { foreground = "default" } +active_style = { foreground = "green" } [theme.guilds_tree] auto_expand_folders = true diff --git a/internal/config/theme.go b/internal/config/theme.go index f43e181..88b8b96 100644 --- a/internal/config/theme.go +++ b/internal/config/theme.go @@ -2,6 +2,7 @@ package config import ( "github.com/ayn2op/tview" + "github.com/gdamore/tcell/v2" ) type BorderSetWrapper struct{ tview.BorderSet } @@ -36,19 +37,46 @@ func (aw *AlignmentWrapper) UnmarshalTOML(v any) error { return nil } +type StyleWrapper struct{ tcell.Style } + +func (sw *StyleWrapper) UnmarshalTOML(v any) error { + m, ok := v.(map[string]any) + if !ok { + return nil + } + + for k, v := range m { + s, ok := v.(string) + if !ok { + continue + } + + switch k { + case "foreground": + color := tcell.GetColor(s) + sw.Style = sw.Foreground(color) + case "background": + color := tcell.GetColor(s) + sw.Style = sw.Background(color) + } + } + + return nil +} + type ( BorderTheme struct { Enabled bool `toml:"enabled"` Padding [4]int `toml:"padding"` Set BorderSetWrapper `toml:"set"` - Color string `toml:"color"` - ActiveColor string `toml:"active_color"` + Style StyleWrapper `toml:"style"` + ActiveStyle StyleWrapper `toml:"active_style"` } TitleTheme struct { - Color string `toml:"color"` - ActiveColor string `toml:"active_color"` + Style StyleWrapper `toml:"style"` + ActiveStyle StyleWrapper `toml:"active_style"` Alignment AlignmentWrapper `toml:"alignment"` } diff --git a/internal/ui/util.go b/internal/ui/util.go index 701f54b..5aff8eb 100644 --- a/internal/ui/util.go +++ b/internal/ui/util.go @@ -3,7 +3,6 @@ package ui import ( "github.com/ayn2op/discordo/internal/config" "github.com/ayn2op/tview" - "github.com/gdamore/tcell/v2" ) func NewConfiguredBox(box *tview.Box, cfg *config.Theme) *tview.Box { @@ -11,22 +10,18 @@ func NewConfiguredBox(box *tview.Box, cfg *config.Theme) *tview.Box { t := cfg.Title p := b.Padding box. + SetBorderStyle(b.Style.Style). SetBorderSet(b.Set.BorderSet). SetBorderPadding(p[0], p[1], p[2], p[3]). + SetTitleStyle(t.Style.Style). SetTitleAlignment(t.Alignment.Alignment). SetFocusFunc(func() { - borderColor := tcell.GetColor(b.ActiveColor) - box.SetBorderStyle(tcell.StyleDefault.Foreground(borderColor)) - - titleColor := tcell.GetColor(t.ActiveColor) - box.SetTitleStyle(tcell.StyleDefault.Foreground(titleColor)) + box.SetBorderStyle(b.ActiveStyle.Style) + box.SetTitleStyle(t.ActiveStyle.Style) }). SetBlurFunc(func() { - borderColor := tcell.GetColor(b.Color) - box.SetBorderStyle(tcell.StyleDefault.Foreground(borderColor)) - - titleColor := tcell.GetColor(t.Color) - box.SetTitleStyle(tcell.StyleDefault.Foreground(titleColor)) + box.SetBorderStyle(b.Style.Style) + box.SetTitleStyle(t.Style.Style) }) if b.Enabled {