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