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:
parent
b43c9485b8
commit
cf661e7e15
50
cfg/common_settings.go
Normal file
50
cfg/common_settings.go
Normal 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
|
||||||
|
}
|
3
main.go
3
main.go
@ -254,7 +254,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
|||||||
case "textfile":
|
case "textfile":
|
||||||
widget = textfile.NewWidget(app, pages)
|
widget = textfile.NewWidget(app, pages)
|
||||||
case "todo":
|
case "todo":
|
||||||
widget = todo.NewWidget(app, pages)
|
cfg := todo.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = todo.NewWidget(app, pages, cfg)
|
||||||
case "todoist":
|
case "todoist":
|
||||||
widget = todoist.NewWidget(app, pages)
|
widget = todoist.NewWidget(app, pages)
|
||||||
case "travisci":
|
case "travisci":
|
||||||
|
23
modules/todo/settings.go
Normal file
23
modules/todo/settings.go
Normal 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
|
||||||
|
}
|
@ -40,18 +40,20 @@ type Widget struct {
|
|||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
app *tview.Application
|
app *tview.Application
|
||||||
|
settings *Settings
|
||||||
filePath string
|
filePath string
|
||||||
list checklist.Checklist
|
list checklist.Checklist
|
||||||
pages *tview.Pages
|
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{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, "Todo", "todo", true),
|
TextWidget: wtf.NewTextWidget(app, "Todo", "todo", true),
|
||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
filePath: wtf.Config.UString("wtf.mods.todo.filename"),
|
settings: settings,
|
||||||
|
filePath: settings.FilePath,
|
||||||
list: checklist.NewChecklist(),
|
list: checklist.NewChecklist(),
|
||||||
pages: pages,
|
pages: pages,
|
||||||
}
|
}
|
||||||
@ -255,11 +257,8 @@ func (widget *Widget) modalFocus(form *tview.Form) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) modalForm(lbl, text string) *tview.Form {
|
func (widget *Widget) modalForm(lbl, text string) *tview.Form {
|
||||||
form := tview.NewForm().
|
form := tview.NewForm().SetFieldBackgroundColor(wtf.ColorFor(widget.settings.Common.Colors.Background))
|
||||||
SetFieldBackgroundColor(wtf.ColorFor(wtf.Config.UString("wtf.colors.background", "black")))
|
form.SetButtonsAlign(tview.AlignCenter).SetButtonTextColor(wtf.ColorFor(widget.settings.Common.Colors.Text))
|
||||||
|
|
||||||
form.SetButtonsAlign(tview.AlignCenter).
|
|
||||||
SetButtonTextColor(wtf.ColorFor(wtf.Config.UString("wtf.colors.text", "white")))
|
|
||||||
|
|
||||||
form.AddInputField(lbl, text, 60, nil, nil)
|
form.AddInputField(lbl, text, 60, nil, nil)
|
||||||
|
|
||||||
|
18
wtf/utils.go
18
wtf/utils.go
@ -96,17 +96,17 @@ func NamesFromEmails(emails []string) []string {
|
|||||||
|
|
||||||
// OpenFile opens the file defined in `path` via the operating system
|
// OpenFile opens the file defined in `path` via the operating system
|
||||||
func OpenFile(path string) {
|
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 {
|
switch runtime.GOOS {
|
||||||
case "linux":
|
case "linux":
|
||||||
exec.Command("xdg-open", path).Start()
|
exec.Command("xdg-open", path).Start()
|
||||||
case "windows":
|
case "windows":
|
||||||
exec.Command("rundll32", "url.dll,FileProtocolHandler", path).Start()
|
exec.Command("rundll32", "url.dll,FileProtocolHandler", path).Start()
|
||||||
case "darwin":
|
case "darwin":
|
||||||
exec.Command("open", path).Start()
|
exec.Command("open", path).Start()
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
filePath, _ := ExpandHomeDir(path)
|
filePath, _ := ExpandHomeDir(path)
|
||||||
openFileUtil := Config.UString("wtf.openFileUtil", "open")
|
openFileUtil := Config.UString("wtf.openFileUtil", "open")
|
||||||
cmd := exec.Command(openFileUtil, filePath)
|
cmd := exec.Command(openFileUtil, filePath)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user