Merge pull request #2 from louy2/guard-signal

Guard signal
This commit is contained in:
Brian Buller 2016-05-09 10:42:24 -05:00
commit ca7e8555bd
3 changed files with 61 additions and 22 deletions

View File

@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"syscall"
"github.com/boltdb/bolt"
"github.com/nsf/termbox-go"
@ -18,27 +17,6 @@ var databaseFile string
var db *bolt.DB
var memBolt *BoltDB
func mainLoop(memBolt *BoltDB, style Style) {
screens := defaultScreensForData(memBolt)
displayScreen := screens[BrowserScreenIndex]
layoutAndDrawScreen(displayScreen, style)
for {
event := termbox.PollEvent()
if event.Type == termbox.EventKey {
newScreenIndex := displayScreen.handleKeyEvent(event)
if newScreenIndex < len(screens) {
displayScreen = screens[newScreenIndex]
layoutAndDrawScreen(displayScreen, style)
} else {
break
}
}
if event.Type == termbox.EventResize {
layoutAndDrawScreen(displayScreen, style)
}
}
}
func main() {
var err error

37
mainloop.go Normal file
View File

@ -0,0 +1,37 @@
// +build !windows
package main
import (
"os"
"syscall"
"github.com/nsf/termbox-go"
)
func mainLoop(memBolt *BoltDB, style Style) {
screens := defaultScreensForData(memBolt)
displayScreen := screens[BrowserScreenIndex]
layoutAndDrawScreen(displayScreen, style)
for {
event := termbox.PollEvent()
if event.Type == termbox.EventKey {
if event.Key == termbox.KeyCtrlZ {
process, _ := os.FindProcess(os.Getpid())
termbox.Close()
process.Signal(syscall.SIGSTOP)
termbox.Init()
}
newScreenIndex := displayScreen.handleKeyEvent(event)
if newScreenIndex < len(screens) {
displayScreen = screens[newScreenIndex]
layoutAndDrawScreen(displayScreen, style)
} else {
break
}
}
if event.Type == termbox.EventResize {
layoutAndDrawScreen(displayScreen, style)
}
}
}

24
mainloop_windows.go Normal file
View File

@ -0,0 +1,24 @@
package main
import "github.com/nsf/termbox-go"
func mainLoop(memBolt *BoltDB, style Style) {
screens := defaultScreensForData(memBolt)
displayScreen := screens[BrowserScreenIndex]
layoutAndDrawScreen(displayScreen, style)
for {
event := termbox.PollEvent()
if event.Type == termbox.EventKey {
newScreenIndex := displayScreen.handleKeyEvent(event)
if newScreenIndex < len(screens) {
displayScreen = screens[newScreenIndex]
layoutAndDrawScreen(displayScreen, style)
} else {
break
}
}
if event.Type == termbox.EventResize {
layoutAndDrawScreen(displayScreen, style)
}
}
}