mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Todo list persists to file
This commit is contained in:
parent
a0ce5eb412
commit
a6e8d64284
@ -3,6 +3,7 @@ package todo
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
@ -64,6 +65,7 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
case " ":
|
case " ":
|
||||||
// Check/uncheck selected item
|
// Check/uncheck selected item
|
||||||
widget.list.Toggle()
|
widget.list.Toggle()
|
||||||
|
widget.persist()
|
||||||
widget.display()
|
widget.display()
|
||||||
return nil
|
return nil
|
||||||
case "e":
|
case "e":
|
||||||
@ -99,3 +101,17 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
return event
|
return event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// persist writes the todo list to Yaml file
|
||||||
|
func (widget *Widget) persist() {
|
||||||
|
confDir, _ := wtf.ConfigDir()
|
||||||
|
filePath := fmt.Sprintf("%s/%s", confDir, widget.FilePath)
|
||||||
|
|
||||||
|
fileData, _ := yaml.Marshal(&widget.list)
|
||||||
|
|
||||||
|
err := ioutil.WriteFile(filePath, fileData, 0644)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user