2016-09-11 17:55:19 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-09-25 22:34:02 +02:00
|
|
|
"flag"
|
2016-10-09 18:37:00 +02:00
|
|
|
"fmt"
|
2016-09-25 22:34:02 +02:00
|
|
|
"log"
|
|
|
|
"os/user"
|
|
|
|
"path"
|
|
|
|
|
2016-10-19 09:08:31 +02:00
|
|
|
"github.com/erroneousboat/slack-term/context"
|
|
|
|
"github.com/erroneousboat/slack-term/handlers"
|
2017-03-17 14:36:29 +01:00
|
|
|
termbox "github.com/nsf/termbox-go"
|
2016-09-11 17:55:19 +02:00
|
|
|
|
|
|
|
"github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
2016-10-09 18:37:00 +02:00
|
|
|
const (
|
2017-03-03 12:59:33 +01:00
|
|
|
VERSION = "v0.2.1"
|
2016-10-30 14:26:12 +01:00
|
|
|
USAGE = `NAME:
|
2016-10-09 18:37:00 +02:00
|
|
|
slack-term - slack client for your terminal
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
slack-term -config [path-to-config]
|
|
|
|
|
|
|
|
VERSION:
|
|
|
|
%s
|
|
|
|
|
|
|
|
GLOBAL OPTIONS:
|
|
|
|
--help, -h
|
|
|
|
`
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
flgConfig string
|
|
|
|
flgUsage bool
|
|
|
|
)
|
2016-09-11 17:55:19 +02:00
|
|
|
|
2016-10-09 18:37:00 +02:00
|
|
|
func init() {
|
2016-09-25 22:34:02 +02:00
|
|
|
// Get home dir for config file default
|
|
|
|
usr, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse flags
|
2016-10-09 18:37:00 +02:00
|
|
|
flag.StringVar(
|
|
|
|
&flgConfig,
|
2016-09-25 22:34:02 +02:00
|
|
|
"config",
|
|
|
|
path.Join(usr.HomeDir, "slack-term.json"),
|
|
|
|
"location of config file",
|
|
|
|
)
|
2016-10-09 18:37:00 +02:00
|
|
|
|
|
|
|
flag.Usage = func() {
|
|
|
|
fmt.Printf(USAGE, VERSION)
|
|
|
|
}
|
|
|
|
|
2016-09-25 22:34:02 +02:00
|
|
|
flag.Parse()
|
2016-10-09 18:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Start terminal user interface
|
|
|
|
err := termui.Init()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer termui.Close()
|
2016-09-25 22:34:02 +02:00
|
|
|
|
|
|
|
// Create context
|
2016-10-09 18:37:00 +02:00
|
|
|
ctx := context.CreateAppContext(flgConfig)
|
2016-09-11 17:55:19 +02:00
|
|
|
|
2016-09-25 22:34:02 +02:00
|
|
|
// Setup body
|
2016-09-11 17:55:19 +02:00
|
|
|
termui.Body.AddRows(
|
|
|
|
termui.NewRow(
|
2016-10-19 18:21:00 +02:00
|
|
|
termui.NewCol(ctx.Config.SidebarWidth, 0, ctx.View.Channels),
|
2016-10-21 16:21:13 +02:00
|
|
|
termui.NewCol(ctx.Config.MainWidth, 0, ctx.View.Chat),
|
2016-09-11 17:55:19 +02:00
|
|
|
),
|
|
|
|
termui.NewRow(
|
2016-10-19 18:21:00 +02:00
|
|
|
termui.NewCol(ctx.Config.SidebarWidth, 0, ctx.View.Mode),
|
2016-10-21 16:21:13 +02:00
|
|
|
termui.NewCol(ctx.Config.MainWidth, 0, ctx.View.Input),
|
2016-09-11 17:55:19 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
termui.Body.Align()
|
|
|
|
termui.Render(termui.Body)
|
|
|
|
|
2016-09-25 22:34:02 +02:00
|
|
|
// Set body in context
|
2016-09-11 17:55:19 +02:00
|
|
|
ctx.Body = termui.Body
|
|
|
|
|
2016-09-25 22:34:02 +02:00
|
|
|
// Register handlers
|
2016-09-11 17:55:19 +02:00
|
|
|
handlers.RegisterEventHandlers(ctx)
|
|
|
|
|
2017-03-17 14:36:29 +01:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
ctx.EventQueue <- termbox.PollEvent()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2016-09-11 17:55:19 +02:00
|
|
|
termui.Loop()
|
|
|
|
}
|