Working on adding persistence
This commit is contained in:
parent
a1a5841f36
commit
a825cb98e6
2
main.go
2
main.go
@ -57,7 +57,7 @@ func mainLoop(style style) {
|
|||||||
|
|
||||||
eventchan := make(chan termbox.Event)
|
eventchan := make(chan termbox.Event)
|
||||||
go readUserInput(eventchan)
|
go readUserInput(eventchan)
|
||||||
go sendRefreshEvent(eventchan)
|
//go sendRefreshEvent(eventchan)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Read User Input
|
// Read User Input
|
||||||
|
@ -7,14 +7,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gogs.bullercodeworks.com/brian/boltrest"
|
||||||
"gogs.bullercodeworks.com/brian/termbox-util"
|
"gogs.bullercodeworks.com/brian/termbox-util"
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
|
||||||
"github.com/nsf/termbox-go"
|
"github.com/nsf/termbox-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
var databaseFile string
|
var databaseFile string
|
||||||
var db *bolt.DB
|
var db *boltrest.DB
|
||||||
|
|
||||||
// TabStops
|
// TabStops
|
||||||
const (
|
const (
|
||||||
@ -29,6 +29,7 @@ type mainScreen struct {
|
|||||||
updateTime time.Time
|
updateTime time.Time
|
||||||
battStat *termboxUtil.ProgressBar
|
battStat *termboxUtil.ProgressBar
|
||||||
notepad *termboxUtil.InputField
|
notepad *termboxUtil.InputField
|
||||||
|
db *boltrest.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (screen *mainScreen) handleKeyPress(event termbox.Event) int {
|
func (screen *mainScreen) handleKeyPress(event termbox.Event) int {
|
||||||
@ -94,7 +95,7 @@ func (screen *mainScreen) performLayout(style style) {
|
|||||||
// Notepad
|
// Notepad
|
||||||
screen.notepad = termboxUtil.CreateInputField(1, 4, (w / 4), (h / 4), style.defaultFg, style.defaultBg)
|
screen.notepad = termboxUtil.CreateInputField(1, 4, (w / 4), (h / 4), style.defaultFg, style.defaultBg)
|
||||||
screen.notepad.SetBordered(true)
|
screen.notepad.SetBordered(true)
|
||||||
screen.notepad.SetWrap(true)
|
//screen.notepad.SetWrap(true)
|
||||||
// TODO: Load saved notepad data
|
// TODO: Load saved notepad data
|
||||||
|
|
||||||
screen.refreshData()
|
screen.refreshData()
|
||||||
@ -142,7 +143,6 @@ func (screen *mainScreen) drawScreen(style style) {
|
|||||||
termboxUtil.DrawStringAtPoint("Notes", screen.notepad.GetX(), screen.notepad.GetY()-1, fg, bg)
|
termboxUtil.DrawStringAtPoint("Notes", screen.notepad.GetX(), screen.notepad.GetY()-1, fg, bg)
|
||||||
fg, bg = style.defaultFg, style.defaultBg
|
fg, bg = style.defaultFg, style.defaultBg
|
||||||
screen.notepad.Draw()
|
screen.notepad.Draw()
|
||||||
termboxUtil.DrawStringAtPoint(screen.notepad.GetValue(), screen.notepad.GetX()+7, screen.notepad.GetY()-1, fg, bg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBatteryPct() int {
|
func getBatteryPct() int {
|
||||||
@ -189,21 +189,17 @@ func getNetworkProfile() string {
|
|||||||
return "Network Info Unavailable"
|
return "Network Info Unavailable"
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadState() {
|
func (screen *mainScreen) loadState() error {
|
||||||
db, err = bolt.Open(databaseFile, 0600, nil)
|
var err error
|
||||||
db.View(func(tx *bolt.Tx) error {
|
db, err = boltrest.Open(databaseFile)
|
||||||
return tx.ForEach(func(nm []byte, b *bolt.Bucket) error {
|
|
||||||
bb, err := readBucket(b)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
bb.name = string(nm)
|
// TODO: Set the boltrest URL
|
||||||
|
screen.db = db
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
})
|
|
||||||
})
|
|
||||||
db.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveState() {
|
func saveState() error {
|
||||||
db, err = bolt.Open(databaseFile, 0600, nil)
|
var err error
|
||||||
db.Close()
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user