Add default mainLoop with syscall
This commit is contained in:
		
							
								
								
									
										37
									
								
								mainloop.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								mainloop.go
									
									
									
									
									
										Normal 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)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user