diff --git a/main.go b/main.go index aaa20b17..5e603178 100644 --- a/main.go +++ b/main.go @@ -196,7 +196,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w cfg := circleci.NewSettingsFromYAML(wtf.Config) widget = circleci.NewWidget(app, cfg) case "clocks": - widget = clocks.NewWidget(app) + cfg := clocks.NewSettingsFromYAML(wtf.Config) + widget = clocks.NewWidget(app, cfg) case "cmdrunner": widget = cmdrunner.NewWidget(app) case "cryptolive": diff --git a/modules/clocks/display.go b/modules/clocks/display.go index 0516e197..9448aa06 100644 --- a/modules/clocks/display.go +++ b/modules/clocks/display.go @@ -2,8 +2,6 @@ package clocks import ( "fmt" - - "github.com/wtfutil/wtf/wtf" ) func (widget *Widget) display(clocks []Clock, dateFormat string, timeFormat string) { @@ -14,9 +12,15 @@ func (widget *Widget) display(clocks []Clock, dateFormat string, timeFormat stri str := "" for idx, clock := range clocks { + rowColor := widget.settings.colors.rows.odd + + if idx%2 == 0 { + rowColor = widget.settings.colors.rows.even + } + str = str + fmt.Sprintf( " [%s]%-12s %-10s %7s[white]\n", - wtf.RowColor("clocks", idx), + rowColor, clock.Label, clock.Time(timeFormat), clock.Date(dateFormat), diff --git a/modules/clocks/setting.go b/modules/clocks/setting.go new file mode 100644 index 00000000..3fbc856a --- /dev/null +++ b/modules/clocks/setting.go @@ -0,0 +1,42 @@ +package clocks + +import ( + "github.com/olebedev/config" + "github.com/wtfutil/wtf/cfg" + "github.com/wtfutil/wtf/wtf" +) + +type colors struct { + rows struct { + even string + odd string + } +} + +type Settings struct { + colors + common *cfg.Common + + dateFormat string + timeFormat string + locations map[string]interface{} + sort string +} + +func NewSettingsFromYAML(ymlConfig *config.Config) *Settings { + localConfig, _ := ymlConfig.Get("wtf.mods.clocks") + + settings := Settings{ + common: cfg.NewCommonSettingsFromYAML(ymlConfig), + + dateFormat: localConfig.UString("dateFormat", wtf.SimpleDateFormat), + timeFormat: localConfig.UString("timeFormat", wtf.SimpleTimeFormat), + locations: localConfig.UMap("locations"), + sort: localConfig.UString("sort"), + } + + settings.colors.rows.even = localConfig.UString("colors.rows.even", "white") + settings.colors.rows.odd = localConfig.UString("colors.rows.odd", "blue") + + return &settings +} diff --git a/modules/clocks/widget.go b/modules/clocks/widget.go index 38d19ac0..11cfc18d 100644 --- a/modules/clocks/widget.go +++ b/modules/clocks/widget.go @@ -14,17 +14,19 @@ type Widget struct { clockColl ClockCollection dateFormat string timeFormat string + settings *Settings } -func NewWidget(app *tview.Application) *Widget { +func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, "World Clocks", "clocks", false), + + settings: settings, + dateFormat: settings.dateFormat, + timeFormat: settings.timeFormat, } - widget.clockColl = widget.buildClockCollection(wtf.Config.UMap("wtf.mods.clocks.locations")) - - widget.dateFormat = wtf.Config.UString("wtf.mods.clocks.dateFormat", wtf.SimpleDateFormat) - widget.timeFormat = wtf.Config.UString("wtf.mods.clocks.timeFormat", wtf.SimpleTimeFormat) + widget.clockColl = widget.buildClockCollection(settings.locations) return &widget }