Permalink
Browse files

Add EventQueue to AppContext

This should alleviate some problems with using the application and
getting the error:

panic: runtime error: slice bounds out of range

However, I'm still able to trigger this event when scrolling
the mouse wheel.

Fixes #47
  • Loading branch information...
erroneousboat committed Mar 17, 2017
1 parent 118f414 commit f8bc4f80063b12ddb0dd5bfd8ea58b8d6ecbbfa6
Showing with 20 additions and 18 deletions.
  1. +12 −9 context/context.go
  2. +1 −9 handlers/event.go
  3. +7 −0 main.go
View
@@ -4,6 +4,7 @@ import (
"log"
"github.com/gizak/termui"
termbox "github.com/nsf/termbox-go"
"github.com/erroneousboat/slack-term/config"
"github.com/erroneousboat/slack-term/service"
@@ -16,11 +17,12 @@ const (
)
type AppContext struct {
Service *service.SlackService
Body *termui.Grid
View *views.View
Config *config.Config
Mode string
EventQueue chan termbox.Event
Service *service.SlackService
Body *termui.Grid
View *views.View
Config *config.Config
Mode string
}
// CreateAppContext creates an application context which can be passed
@@ -39,9 +41,10 @@ func CreateAppContext(flgConfig string) *AppContext {
view := views.CreateChatView(svc)
return &AppContext{
Service: svc,
View: view,
Config: config,
Mode: CommandMode,
EventQueue: make(chan termbox.Event, 20),
Service: svc,
View: view,
Config: config,
Mode: CommandMode,
}
}
View
@@ -43,17 +43,9 @@ func RegisterEventHandlers(ctx *context.AppContext) {
}
func anyKeyHandler(ctx *context.AppContext) {
eventQueue := make(chan termbox.Event, 5)
go func() {
for {
eventQueue <- termbox.PollEvent()
}
}()
go func() {
for {
ev := <-eventQueue
ev := <-ctx.EventQueue
if ev.Type != termbox.EventKey {
continue
View
@@ -9,6 +9,7 @@ import (
"github.com/erroneousboat/slack-term/context"
"github.com/erroneousboat/slack-term/handlers"
termbox "github.com/nsf/termbox-go"
"github.com/gizak/termui"
)
@@ -87,5 +88,11 @@ func main() {
// Register handlers
handlers.RegisterEventHandlers(ctx)
go func() {
for {
ctx.EventQueue <- termbox.PollEvent()
}
}()
termui.Loop()
}

0 comments on commit f8bc4f8

Please sign in to comment.