sluice/context.go

46 lines
887 B
Go

package main
import (
"github.com/gizak/termui"
termbox "github.com/nsf/termbox-go"
)
const (
CommandMode = "command"
InsertMode = "insert"
SearchMode = "search"
)
type AppContext struct {
EventQueue chan termbox.Event
Service *SlackService
Body *termui.Grid
View *View
Config *Config
Mode string
}
// CreateAppContext creates an application context which can be passed
// and referenced througout the application
func CreateAppContext(flgConfig string) (*AppContext, error) {
// Load config
config, err := NewConfig(flgConfig)
if err != nil {
return nil, err
}
// Create Service
svc := NewSlackService(config.SlackToken)
// Create ChatView
view := CreateChatView(svc)
return &AppContext{
EventQueue: make(chan termbox.Event, 20),
Service: svc,
View: view,
Config: config,
Mode: CommandMode,
}, nil
}