53 lines
1.1 KiB
Go
Raw Normal View History

2016-09-11 17:55:19 +02:00
package context
import (
2017-09-23 13:56:45 +02:00
"github.com/erroneousboat/termui"
termbox "github.com/nsf/termbox-go"
2016-09-25 22:34:02 +02:00
2016-10-19 09:08:31 +02:00
"github.com/erroneousboat/slack-term/config"
"github.com/erroneousboat/slack-term/service"
"github.com/erroneousboat/slack-term/views"
2016-09-11 17:55:19 +02:00
)
const (
CommandMode = "command"
InsertMode = "insert"
2017-07-15 23:56:39 +02:00
SearchMode = "search"
2016-09-11 17:55:19 +02:00
)
type AppContext struct {
EventQueue chan termbox.Event
Service *service.SlackService
Body *termui.Grid
View *views.View
Config *config.Config
Mode string
2016-09-11 17:55:19 +02:00
}
2016-10-02 16:07:35 +02:00
// CreateAppContext creates an application context which can be passed
// and referenced througout the application
func CreateAppContext(flgConfig string) (*AppContext, error) {
2016-09-25 22:34:02 +02:00
// Load config
config, err := config.NewConfig(flgConfig)
if err != nil {
return nil, err
2016-09-25 22:34:02 +02:00
}
// Create Service
svc, err := service.NewSlackService(config.SlackToken)
if err != nil {
return nil, err
}
2016-09-25 22:34:02 +02:00
// Create ChatView
view := views.CreateChatView(svc)
2016-09-11 17:55:19 +02:00
return &AppContext{
EventQueue: make(chan termbox.Event, 20),
Service: svc,
View: view,
Config: config,
Mode: CommandMode,
}, nil
2016-09-11 17:55:19 +02:00
}