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:
parent
1630fb96b7
commit
37356679cc
3
main.go
3
main.go
@ -196,7 +196,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
|||||||
cfg := circleci.NewSettingsFromYAML(wtf.Config)
|
cfg := circleci.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = circleci.NewWidget(app, cfg)
|
widget = circleci.NewWidget(app, cfg)
|
||||||
case "clocks":
|
case "clocks":
|
||||||
widget = clocks.NewWidget(app)
|
cfg := clocks.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = clocks.NewWidget(app, cfg)
|
||||||
case "cmdrunner":
|
case "cmdrunner":
|
||||||
widget = cmdrunner.NewWidget(app)
|
widget = cmdrunner.NewWidget(app)
|
||||||
case "cryptolive":
|
case "cryptolive":
|
||||||
|
@ -2,8 +2,6 @@ package clocks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/wtfutil/wtf/wtf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display(clocks []Clock, dateFormat string, timeFormat string) {
|
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 := ""
|
str := ""
|
||||||
for idx, clock := range clocks {
|
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(
|
str = str + fmt.Sprintf(
|
||||||
" [%s]%-12s %-10s %7s[white]\n",
|
" [%s]%-12s %-10s %7s[white]\n",
|
||||||
wtf.RowColor("clocks", idx),
|
rowColor,
|
||||||
clock.Label,
|
clock.Label,
|
||||||
clock.Time(timeFormat),
|
clock.Time(timeFormat),
|
||||||
clock.Date(dateFormat),
|
clock.Date(dateFormat),
|
||||||
|
42
modules/clocks/setting.go
Normal file
42
modules/clocks/setting.go
Normal 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
|
||||||
|
}
|
@ -14,17 +14,19 @@ type Widget struct {
|
|||||||
clockColl ClockCollection
|
clockColl ClockCollection
|
||||||
dateFormat string
|
dateFormat string
|
||||||
timeFormat string
|
timeFormat string
|
||||||
|
settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, "World Clocks", "clocks", false),
|
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.clockColl = widget.buildClockCollection(settings.locations)
|
||||||
|
|
||||||
widget.dateFormat = wtf.Config.UString("wtf.mods.clocks.dateFormat", wtf.SimpleDateFormat)
|
|
||||||
widget.timeFormat = wtf.Config.UString("wtf.mods.clocks.timeFormat", wtf.SimpleTimeFormat)
|
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user