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
This commit is contained in:
parent
118f414aba
commit
f8bc4f8006
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
7
main.go
7
main.go
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user