80 lines
1.6 KiB
Go
80 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/nsf/termbox-go"
|
|
"os"
|
|
//"syscall"
|
|
"time"
|
|
)
|
|
|
|
const PROGRAM_NAME = "tis100e"
|
|
|
|
func readUserInput(e chan termbox.Event) {
|
|
for {
|
|
e <- termbox.PollEvent()
|
|
}
|
|
}
|
|
|
|
func sendNoneEvent(e chan termbox.Event) {
|
|
for {
|
|
time.Sleep(60 * time.Millisecond)
|
|
e <- termbox.Event{Type: termbox.EventNone}
|
|
}
|
|
}
|
|
|
|
func mainLoop(style Style) {
|
|
screens := defaultScreens()
|
|
display_screen := screens[MAIN_SCREEN_INDEX]
|
|
layoutAndDrawScreen(display_screen, style)
|
|
eventchan := make(chan termbox.Event)
|
|
go readUserInput(eventchan)
|
|
go sendNoneEvent(eventchan)
|
|
|
|
for {
|
|
event := <-eventchan // := termbox.PollEvent()
|
|
if event.Type == termbox.EventKey {
|
|
if event.Key == termbox.KeyCtrlZ || event.Key == termbox.KeyCtrlC {
|
|
/*
|
|
process, _ := os.FindProcess(os.Getpid())
|
|
termbox.Close()
|
|
process.Signal(syscall.SIGSTOP)
|
|
termbox.Init()
|
|
*/
|
|
break
|
|
}
|
|
new_screen_index := display_screen.handleKeyEvent(event)
|
|
if new_screen_index < len(screens) {
|
|
display_screen = screens[new_screen_index]
|
|
layoutAndDrawScreen(display_screen, style)
|
|
} else if new_screen_index == EXIT_SCREEN_INDEX {
|
|
break
|
|
}
|
|
}
|
|
if event.Type == termbox.EventResize || event.Type == termbox.EventNone {
|
|
layoutAndDrawScreen(display_screen, style)
|
|
}
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
var err error
|
|
|
|
err = termbox.Init()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer termbox.Close()
|
|
|
|
style := defaultStyle()
|
|
termbox.SetOutputMode(termbox.Output256)
|
|
mainLoop(style)
|
|
}
|
|
|
|
func WriteToLog(d string) {
|
|
f, err := os.OpenFile("tis100e_log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0664)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
f.WriteString(d)
|
|
f.Close()
|
|
} |