Working on adding persistence

This commit is contained in:
Brian Buller 2016-01-02 22:13:14 -06:00
parent a1a5841f36
commit a825cb98e6
2 changed files with 16 additions and 20 deletions

View File

@ -57,7 +57,7 @@ func mainLoop(style style) {
eventchan := make(chan termbox.Event)
go readUserInput(eventchan)
go sendRefreshEvent(eventchan)
//go sendRefreshEvent(eventchan)
for {
// Read User Input

View File

@ -7,14 +7,14 @@ import (
"strings"
"time"
"gogs.bullercodeworks.com/brian/boltrest"
"gogs.bullercodeworks.com/brian/termbox-util"
"github.com/boltdb/bolt"
"github.com/nsf/termbox-go"
)
var databaseFile string
var db *bolt.DB
var db *boltrest.DB
// TabStops
const (
@ -29,6 +29,7 @@ type mainScreen struct {
updateTime time.Time
battStat *termboxUtil.ProgressBar
notepad *termboxUtil.InputField
db *boltrest.DB
}
func (screen *mainScreen) handleKeyPress(event termbox.Event) int {
@ -94,7 +95,7 @@ func (screen *mainScreen) performLayout(style style) {
// Notepad
screen.notepad = termboxUtil.CreateInputField(1, 4, (w / 4), (h / 4), style.defaultFg, style.defaultBg)
screen.notepad.SetBordered(true)
screen.notepad.SetWrap(true)
//screen.notepad.SetWrap(true)
// TODO: Load saved notepad data
screen.refreshData()
@ -142,7 +143,6 @@ func (screen *mainScreen) drawScreen(style style) {
termboxUtil.DrawStringAtPoint("Notes", screen.notepad.GetX(), screen.notepad.GetY()-1, fg, bg)
fg, bg = style.defaultFg, style.defaultBg
screen.notepad.Draw()
termboxUtil.DrawStringAtPoint(screen.notepad.GetValue(), screen.notepad.GetX()+7, screen.notepad.GetY()-1, fg, bg)
}
func getBatteryPct() int {
@ -189,21 +189,17 @@ func getNetworkProfile() string {
return "Network Info Unavailable"
}
func loadState() {
db, err = bolt.Open(databaseFile, 0600, nil)
db.View(func(tx *bolt.Tx) error {
return tx.ForEach(func(nm []byte, b *bolt.Bucket) error {
bb, err := readBucket(b)
if err == nil {
bb.name = string(nm)
}
return err
})
})
db.Close()
func (screen *mainScreen) loadState() error {
var err error
db, err = boltrest.Open(databaseFile)
if err == nil {
// TODO: Set the boltrest URL
screen.db = db
}
return err
}
func saveState() {
db, err = bolt.Open(databaseFile, 0600, nil)
db.Close()
func saveState() error {
var err error
return err
}