From ef71ad2ced031276f5e80f1ee8eb68a29597f3d7 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 1 Oct 2019 22:03:29 -0700 Subject: [PATCH] WTF-658 Clocks obeys global row color settings Fixes #658. --- modules/clocks/display.go | 8 +------- modules/clocks/settings.go | 13 ++----------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/modules/clocks/display.go b/modules/clocks/display.go index 36379b1f..7c1a5bca 100644 --- a/modules/clocks/display.go +++ b/modules/clocks/display.go @@ -11,15 +11,9 @@ func (widget *Widget) display(clocks []Clock, dateFormat string, timeFormat stri } else { for idx, clock := range clocks { - rowColor := widget.settings.colors.rows.odd - - if idx%2 == 0 { - rowColor = widget.settings.colors.rows.even - } - str += fmt.Sprintf( " [%s]%-12s %-10s %7s[white]\n", - rowColor, + widget.CommonSettings().RowColor(idx), clock.Label, clock.Time(timeFormat), clock.Date(dateFormat), diff --git a/modules/clocks/settings.go b/modules/clocks/settings.go index 113f454e..4106dcaf 100644 --- a/modules/clocks/settings.go +++ b/modules/clocks/settings.go @@ -11,15 +11,8 @@ const ( defaultTitle = "Clocks" ) -type colors struct { - rows struct { - even string - odd string - } -} - +// Settings defines the configuration properties for this module type Settings struct { - colors common *cfg.Common dateFormat string `help:"The format of the date string for all clocks." values:"Any valid Go date layout which is handled by Time.Format. Defaults to Jan 2."` @@ -28,6 +21,7 @@ type Settings struct { sort string `help:"Defines the display order of the clocks in the widget." values:"'alphabetical' or 'chronological'. 'alphabetical' will sort in acending order by key, 'chronological' will sort in ascending order by date/time."` } +// NewSettingsFromYAML creates a new settings instance from a YAML config block func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { settings := Settings{ common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), @@ -38,8 +32,5 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co sort: ymlConfig.UString("sort"), } - settings.colors.rows.even = ymlConfig.UString("colors.rows.even", "white") - settings.colors.rows.odd = ymlConfig.UString("colors.rows.odd", "blue") - return &settings }