2016-09-11 17:55:19 +02:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
2017-09-23 13:56:45 +02:00
|
|
|
"github.com/erroneousboat/termui"
|
2017-03-17 14:36:29 +01:00
|
|
|
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 {
|
2017-03-17 14:36:29 +01:00
|
|
|
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
|
2017-08-04 10:22:42 +02:00
|
|
|
func CreateAppContext(flgConfig string) (*AppContext, error) {
|
2016-09-25 22:34:02 +02:00
|
|
|
// Load config
|
|
|
|
config, err := config.NewConfig(flgConfig)
|
|
|
|
if err != nil {
|
2017-08-04 10:22:42 +02:00
|
|
|
return nil, err
|
2016-09-25 22:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create Service
|
|
|
|
svc := service.NewSlackService(config.SlackToken)
|
|
|
|
|
|
|
|
// Create ChatView
|
|
|
|
view := views.CreateChatView(svc)
|
2016-09-11 17:55:19 +02:00
|
|
|
|
|
|
|
return &AppContext{
|
2017-03-17 14:36:29 +01:00
|
|
|
EventQueue: make(chan termbox.Event, 20),
|
|
|
|
Service: svc,
|
|
|
|
View: view,
|
|
|
|
Config: config,
|
|
|
|
Mode: CommandMode,
|
2017-08-04 10:22:42 +02:00
|
|
|
}, nil
|
2016-09-11 17:55:19 +02:00
|
|
|
}
|