Skip to content

Commit

Permalink
Update termbox handlers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jpbruinsslot committed Aug 19, 2017
1 parent c88dff2 commit 0e89f0e
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions handlers/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -54,18 +54,38 @@ func eventHandler(ctx *context.AppContext) {
go func() {
for {
ev := <-ctx.EventQueue
handleTermboxEvents(ctx, ev)
handleMoreTermboxEvents(ctx, ev)
}
}()
}

func handleTermboxEvents(ctx *context.AppContext, ev termbox.Event) bool {
switch ev.Type {
case termbox.EventKey:
actionKeyEvent(ctx, ev)
case termbox.EventResize:
actionResizeEvent(ctx, ev)
}

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 incomingMessageHandler(ctx *context.AppContext) {
func messageHandler(ctx *context.AppContext) {
go func() {
for {
select {
Expand Down

0 comments on commit 0e89f0e

Please sign in to comment.