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

WTF-658 Clocks obeys global row color settings #669

Merged
merged 1 commit into from
Oct 3, 2019
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
8 changes: 1 addition & 7 deletions modules/clocks/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 2 additions & 11 deletions modules/clocks/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."`
Expand All @@ -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),
Expand All @@ -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
}