Update termbox handlers

termbox.PollEvent sometimes trigger a panic whil typing in the
input box (#58). I took note from https://github.com/nsf/godit
and implemented and extra event handler that should potentially
handle more events from termbox.
This commit is contained in:
erroneousboat 2017-08-05 11:46:15 +02:00
parent 58652a7baf
commit 36e263329c

View File

@ -41,7 +41,7 @@ var actionMap = map[string]func(*context.AppContext){
func RegisterEventHandlers(ctx *context.AppContext) {
eventHandler(ctx)
incomingMessageHandler(ctx)
messageHandler(ctx)
}
func eventHandler(ctx *context.AppContext) {
@ -54,18 +54,38 @@ func eventHandler(ctx *context.AppContext) {
go func() {
for {
ev := <-ctx.EventQueue
switch ev.Type {
case termbox.EventKey:
actionKeyEvent(ctx, ev)
case termbox.EventResize:
actionResizeEvent(ctx, ev)
}
handleTermboxEvents(ctx, ev)
handleMoreTermboxEvents(ctx, ev)
}
}()
}
func incomingMessageHandler(ctx *context.AppContext) {
func handleTermboxEvents(ctx *context.AppContext, ev termbox.Event) bool {
switch ev.Type {
case termbox.EventKey:
actionKeyEvent(ctx, ev)
case termbox.EventResize:
actionResizeEvent(ctx, ev)
}
return true
}
func handleMoreTermboxEvents(ctx *context.AppContext, ev termbox.Event) bool {
for {
select {
case ev := <- ctx.EventQueue:
ok := handleTermboxEvents(ctx, ev)
if !ok {
return false
}
default:
return true
}
}
}
func messageHandler(ctx *context.AppContext) {
go func() {
for {
select {