diff --git a/cfg/common_settings.go b/cfg/common_settings.go new file mode 100644 index 00000000..ef0d29a2 --- /dev/null +++ b/cfg/common_settings.go @@ -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 +} diff --git a/main.go b/main.go index a9f92bbd..9d37b7e1 100644 --- a/main.go +++ b/main.go @@ -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": diff --git a/modules/todo/settings.go b/modules/todo/settings.go new file mode 100644 index 00000000..308f5b79 --- /dev/null +++ b/modules/todo/settings.go @@ -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 +} diff --git a/modules/todo/widget.go b/modules/todo/widget.go index 5f0abeba..16b30fbd 100644 --- a/modules/todo/widget.go +++ b/modules/todo/widget.go @@ -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) diff --git a/wtf/utils.go b/wtf/utils.go index 234788d6..c8e8ae01 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -96,17 +96,17 @@ func NamesFromEmails(emails []string) []string { // OpenFile opens the file defined in `path` via the operating system func OpenFile(path string) { - if (strings.HasPrefix(path,"http://"))||(strings.HasPrefix(path,"https://")) { + if (strings.HasPrefix(path, "http://")) || (strings.HasPrefix(path, "https://")) { switch runtime.GOOS { - case "linux": - exec.Command("xdg-open", path).Start() - case "windows": - exec.Command("rundll32", "url.dll,FileProtocolHandler", path).Start() - case "darwin": - exec.Command("open", path).Start() - default: + case "linux": + exec.Command("xdg-open", path).Start() + case "windows": + exec.Command("rundll32", "url.dll,FileProtocolHandler", path).Start() + case "darwin": + exec.Command("open", path).Start() + default: } - }else { + } else { filePath, _ := ExpandHomeDir(path) openFileUtil := Config.UString("wtf.openFileUtil", "open") cmd := exec.Command(openFileUtil, filePath)