2019-02-15 17:15:26 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
termbox "github.com/nsf/termbox-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
func uiLoop() int {
|
|
|
|
err := termbox.Init()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
termbox.SetOutputMode(termbox.Output256)
|
|
|
|
app.BuildScreens()
|
|
|
|
displayScreen := app.screens[ScreenMain]
|
|
|
|
bundle := Bundle{}
|
|
|
|
bundle.setValue(MainBundleListKey, MainBundleListTodo)
|
|
|
|
|
|
|
|
displayScreen.initialize(bundle)
|
|
|
|
app.layoutAndDrawScreen(displayScreen)
|
|
|
|
eventChan := make(chan termbox.Event)
|
|
|
|
go readUserInput(eventChan)
|
2019-02-26 19:22:37 +00:00
|
|
|
go checkForUpdate(eventChan)
|
2019-02-15 17:15:26 +00:00
|
|
|
for {
|
|
|
|
event := <-eventChan
|
|
|
|
if event.Type == termbox.EventKey {
|
|
|
|
if event.Key == termbox.KeyCtrlC {
|
|
|
|
break
|
|
|
|
} else if event.Key == termbox.KeyCtrlZ {
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
process, _ := os.FindProcess(os.Getpid())
|
|
|
|
termbox.Close()
|
|
|
|
process.Signal(syscall.SIGSTOP)
|
|
|
|
termbox.Init()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newScreenIndex := displayScreen.handleKeyEvent(event)
|
|
|
|
if newScreenIndex < len(app.screens) {
|
|
|
|
displayScreen = app.screens[newScreenIndex]
|
|
|
|
app.layoutAndDrawScreen(displayScreen)
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if event.Type == termbox.EventResize {
|
2019-02-21 16:47:08 +00:00
|
|
|
displayScreen.initialize(nil)
|
2019-02-15 17:15:26 +00:00
|
|
|
app.layoutAndDrawScreen(displayScreen)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
termbox.Close()
|
|
|
|
// Any wrap up should be done here...
|
|
|
|
return 0
|
|
|
|
}
|