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

WTF-400 Todo extracted to new config format

This commit is contained in:
Chris Cummer 2019-04-13 10:07:53 -07:00
parent b43c9485b8
commit cf661e7e15
5 changed files with 90 additions and 17 deletions

50
cfg/common_settings.go Normal file
View File

@ -0,0 +1,50 @@
package cfg
import (
"github.com/olebedev/config"
)
type Colors struct {
Background string
BorderFocusable string
BorderFocused string
BorderNormal string
Checked string
HighlightFore string
HighlightBack string
Text string
}
type Position struct {
Height int
Left int
Top int
Width int
}
type Common struct {
Colors
Position
Enabled bool
RefreshInterval int
Title string
}
func NewCommonSettingsFromYAML(ymlConfig *config.Config) *Common {
common := Common{
Colors: Colors{
Background: ymlConfig.UString("wtf.colors.background", "black"),
BorderFocusable: ymlConfig.UString("wtf.colors.border.focusable"),
BorderFocused: ymlConfig.UString("wtf.colors.border.focused"),
BorderNormal: ymlConfig.UString("wtf.colors.border.normal"),
Checked: ymlConfig.UString("wtf.colors.checked"),
HighlightFore: ymlConfig.UString("wtf.colors.highlight.fore"),
HighlightBack: ymlConfig.UString("wtf.colors.highlight.back"),
Text: ymlConfig.UString("wtf.colors.text", "white"),
},
Position: Position{},
}
return &common
}

View File

@ -254,7 +254,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
case "textfile":
widget = textfile.NewWidget(app, pages)
case "todo":
widget = todo.NewWidget(app, pages)
cfg := todo.NewSettingsFromYAML(wtf.Config)
widget = todo.NewWidget(app, pages, cfg)
case "todoist":
widget = todoist.NewWidget(app, pages)
case "travisci":

23
modules/todo/settings.go Normal file
View File

@ -0,0 +1,23 @@
package todo
import (
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
)
type Settings struct {
Common *cfg.Common
FilePath string
}
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
localConfig, _ := ymlConfig.Get("wtf.mods.todo")
settings := Settings{
Common: cfg.NewCommonSettingsFromYAML(ymlConfig),
FilePath: localConfig.UString("filename"),
}
return &settings
}

View File

@ -40,18 +40,20 @@ type Widget struct {
wtf.TextWidget
app *tview.Application
settings *Settings
filePath string
list checklist.Checklist
pages *tview.Pages
}
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
widget := Widget{
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget(app, "Todo", "todo", true),
app: app,
filePath: wtf.Config.UString("wtf.mods.todo.filename"),
settings: settings,
filePath: settings.FilePath,
list: checklist.NewChecklist(),
pages: pages,
}
@ -255,11 +257,8 @@ func (widget *Widget) modalFocus(form *tview.Form) {
}
func (widget *Widget) modalForm(lbl, text string) *tview.Form {
form := tview.NewForm().
SetFieldBackgroundColor(wtf.ColorFor(wtf.Config.UString("wtf.colors.background", "black")))
form.SetButtonsAlign(tview.AlignCenter).
SetButtonTextColor(wtf.ColorFor(wtf.Config.UString("wtf.colors.text", "white")))
form := tview.NewForm().SetFieldBackgroundColor(wtf.ColorFor(widget.settings.Common.Colors.Background))
form.SetButtonsAlign(tview.AlignCenter).SetButtonTextColor(wtf.ColorFor(widget.settings.Common.Colors.Text))
form.AddInputField(lbl, text, 60, nil, nil)