48 lines
961 B
Go
Raw Normal View History

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
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"
)
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-10-02 16:07:35 +02:00
// CreateAppContext creates an application context which can be passed
// and referenced througout the application
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): %s", flgConfig, 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{
2016-09-25 22:34:02 +02:00
Service: svc,
View: view,
Config: config,
Mode: CommandMode,
2016-09-11 17:55:19 +02:00
}
}