2016-09-11 17:55:19 +02:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
2016-09-25 22:34:02 +02:00
|
|
|
"log"
|
|
|
|
|
2016-09-11 17:55:19 +02:00
|
|
|
"github.com/gizak/termui"
|
2016-09-25 22:34:02 +02:00
|
|
|
|
|
|
|
"github.com/erroneousboat/slack-term/src/config"
|
|
|
|
"github.com/erroneousboat/slack-term/src/service"
|
|
|
|
"github.com/erroneousboat/slack-term/src/views"
|
2016-09-11 17:55:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
CommandMode = "command"
|
|
|
|
InsertMode = "insert"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AppContext struct {
|
2016-09-25 22:34:02 +02:00
|
|
|
Service *service.SlackService
|
|
|
|
Body *termui.Grid
|
|
|
|
View *views.View
|
|
|
|
Config *config.Config
|
|
|
|
Mode string
|
2016-09-11 17:55:19 +02:00
|
|
|
}
|
|
|
|
|
2016-09-25 22:34:02 +02:00
|
|
|
func CreateAppContext(flgConfig string) *AppContext {
|
|
|
|
// Load config
|
|
|
|
config, err := config.NewConfig(flgConfig)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("ERROR: not able to load config file: %s", flgConfig)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Service
|
|
|
|
svc := service.NewSlackService(config.SlackToken)
|
|
|
|
|
|
|
|
// Create ChatView
|
|
|
|
view := views.CreateChatView(svc)
|
2016-09-11 17:55:19 +02:00
|
|
|
|
|
|
|
return &AppContext{
|
2016-09-25 22:34:02 +02:00
|
|
|
Service: svc,
|
|
|
|
View: view,
|
|
|
|
Config: config,
|
|
|
|
Mode: CommandMode,
|
2016-09-11 17:55:19 +02:00
|
|
|
}
|
|
|
|
}
|