77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/nsf/termbox-go"
|
|
)
|
|
|
|
func main() {
|
|
//battPct = getBatteryPct()
|
|
//fmt.Printf("Battery: %d\n", getBatteryPct())
|
|
var err error
|
|
|
|
err = termbox.Init()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer termbox.Close()
|
|
|
|
style := defaultStyle()
|
|
termbox.SetOutputMode(termbox.Output256)
|
|
mainLoop(style)
|
|
}
|
|
|
|
func mainLoop(style style) {
|
|
screens := defaultScreens()
|
|
displayScreen := screens[mainScreenIndex]
|
|
layoutAndDrawScreen(displayScreen, style)
|
|
|
|
for {
|
|
event := termbox.PollEvent()
|
|
if event.Type == termbox.EventKey {
|
|
if event.Key == termbox.KeyCtrlC {
|
|
break
|
|
}
|
|
newScreenIndex := displayScreen.handleKeyEvent(event)
|
|
if newScreenIndex < len(screens) {
|
|
displayScreen = screens[newScreenIndex]
|
|
layoutAndDrawScreen(displayScreen, style)
|
|
} else if newScreenIndex == exitScreenIndex {
|
|
break
|
|
}
|
|
}
|
|
if event.Type == termbox.EventResize || event.Type == termbox.EventNone {
|
|
layoutAndDrawScreen(displayScreen, style)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Screens Setup
|
|
const (
|
|
mainScreenIndex = iota
|
|
//aboutScreenIndex
|
|
exitScreenIndex
|
|
)
|
|
|
|
func defaultScreens() []Screen {
|
|
//var view_port ViewPort
|
|
mainScreen := mainScreen{}
|
|
//aboutScreen := aboutScreen{}
|
|
screens := [...]Screen{
|
|
&mainScreen,
|
|
// &aboutScreen,
|
|
}
|
|
return screens[:]
|
|
}
|
|
|
|
// WriteToLog Writes to the Log
|
|
func WriteToLog(d string) {
|
|
f, err := os.OpenFile("system-status.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0664)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
f.WriteString(d)
|
|
f.Close()
|
|
}
|