Merge branch 'master' of gogs.bullercodeworks.com:brian/utility-screen
This commit is contained in:
commit
a0aea166eb
5
.gitignore
vendored
5
.gitignore
vendored
@ -24,4 +24,7 @@ _testmain.go
|
||||
utility-screen
|
||||
|
||||
# Log file
|
||||
utility-screen.log
|
||||
*.log
|
||||
|
||||
# DB File
|
||||
*.db
|
18
main.go
18
main.go
@ -1,23 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"gogs.bullercodeworks.com/brian/boltrest"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
// ScreenState keeps some app-wide variables
|
||||
type ScreenState struct {
|
||||
updateFreq time.Duration
|
||||
autoUpdate bool
|
||||
updateFreq time.Duration
|
||||
autoUpdate bool
|
||||
databaseFile string
|
||||
db *boltrest.DB
|
||||
}
|
||||
|
||||
var state *ScreenState
|
||||
|
||||
func main() {
|
||||
state = new(ScreenState)
|
||||
state.databaseFile = "utility-screen.db"
|
||||
|
||||
var err error
|
||||
state.db, err = boltrest.Open(state.databaseFile)
|
||||
if err != nil {
|
||||
fmt.Print("Error opening config DB")
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
// TODO: Load config from DB
|
||||
|
||||
err = termbox.Init()
|
||||
if err != nil {
|
||||
|
@ -2,20 +2,17 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gogs.bullercodeworks.com/brian/boltrest"
|
||||
"gogs.bullercodeworks.com/brian/termbox-util"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
var databaseFile string
|
||||
var db *boltrest.DB
|
||||
|
||||
// TabStops
|
||||
const (
|
||||
tabMain = iota
|
||||
@ -29,8 +26,6 @@ type mainScreen struct {
|
||||
updateTime time.Time
|
||||
battStat *termboxUtil.ProgressBar
|
||||
notepad *termboxUtil.InputField
|
||||
db *boltrest.DB
|
||||
scrollFrame *termboxUtil.ScrollFrame
|
||||
}
|
||||
|
||||
func (screen *mainScreen) handleKeyPress(event termbox.Event) int {
|
||||
@ -43,9 +38,10 @@ func (screen *mainScreen) handleKeyPress(event termbox.Event) int {
|
||||
case tabMain:
|
||||
// Main Screen key handling
|
||||
if event.Key == termbox.KeyEsc {
|
||||
return exitScreenIndex
|
||||
//return exitScreenIndex
|
||||
} else if event.Ch == 'r' {
|
||||
// Refresh data
|
||||
screen.loadState()
|
||||
screen.refreshData()
|
||||
} else if event.Ch == 'q' {
|
||||
return exitScreenIndex
|
||||
@ -57,6 +53,8 @@ func (screen *mainScreen) handleKeyPress(event termbox.Event) int {
|
||||
screen.scrollFrame.ScrollDown()
|
||||
} else if event.Key == termbox.KeyArrowLeft {
|
||||
screen.scrollFrame.ScrollLeft()
|
||||
} else if event.Ch == 's' {
|
||||
screen.saveState()
|
||||
}
|
||||
case tabNotepad:
|
||||
// Notepad key handling
|
||||
@ -84,6 +82,8 @@ func (screen *mainScreen) increaseUpdateFreq() {
|
||||
func (screen *mainScreen) refreshData() {
|
||||
screen.updateTime = time.Now()
|
||||
screen.battStat.SetProgress(getBatteryPct())
|
||||
// TODO: Load saved notepad data
|
||||
//screen.loadState()
|
||||
}
|
||||
|
||||
func (screen *mainScreen) performLayout(style style) {
|
||||
@ -125,6 +125,8 @@ func (screen *mainScreen) performLayout(style style) {
|
||||
aa = append(aa, "0123456789012345678901234567890123456789")
|
||||
screen.scrollFrame.AddControl(termboxUtil.CreateASCIIArt(aa, 1, 1, style.defaultFg, style.defaultBg))
|
||||
|
||||
// Multiline is currently disabled
|
||||
//screen.notepad.SetMultiline(true)
|
||||
screen.refreshData()
|
||||
}
|
||||
if time.Since(time.Now()) <= time.Minute {
|
||||
@ -199,6 +201,7 @@ func getBatteryPct() int {
|
||||
}
|
||||
|
||||
func getNetworkProfile() string {
|
||||
// TODO: Make it work with wicd too
|
||||
netApp := "netctl"
|
||||
netArg1 := "list"
|
||||
cmd := exec.Command(netApp, netArg1)
|
||||
@ -219,15 +222,20 @@ func getNetworkProfile() string {
|
||||
|
||||
func (screen *mainScreen) loadState() error {
|
||||
var err error
|
||||
db, err = boltrest.Open(databaseFile)
|
||||
if err == nil {
|
||||
// TODO: Set the boltrest URL
|
||||
screen.db = db
|
||||
var noteVal string
|
||||
if noteVal, err = state.db.GetValue([]string{"mainScreen", "notepad"}, "value"); err == nil {
|
||||
screen.notepad.SetValue(noteVal)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func saveState() error {
|
||||
func (screen *mainScreen) saveState() error {
|
||||
var err error
|
||||
noteVal := screen.notepad.GetValue()
|
||||
WriteToLog(noteVal)
|
||||
if err = state.db.SetValue([]string{"mainScreen", "notepad"}, "value", noteVal); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user