1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-400 Clocks extracted to new config format

This commit is contained in:
Chris Cummer 2019-04-13 18:46:46 -07:00
parent 1630fb96b7
commit 37356679cc
4 changed files with 58 additions and 9 deletions

View File

@ -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":

View File

@ -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),

42
modules/clocks/setting.go Normal file
View File

@ -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
}

View File

@ -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
}