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"
|
2017-08-04 10:22:42 +02:00
|
|
|
"os"
|
2016-09-25 22:34:02 +02:00
|
|
|
"os/user"
|
|
|
|
"path"
|
|
|
|
|
2017-09-23 13:56:45 +02:00
|
|
|
"github.com/erroneousboat/termui"
|
2017-08-04 10:22:42 +02:00
|
|
|
termbox "github.com/nsf/termbox-go"
|
2016-09-11 17:55:19 +02:00
|
|
|
|
2017-09-23 13:56:45 +02:00
|
|
|
"github.com/erroneousboat/slack-term/context"
|
|
|
|
"github.com/erroneousboat/slack-term/handlers"
|
2016-09-11 17:55:19 +02:00
|
|
|
)
|
|
|
|
|
2016-10-09 18:37:00 +02:00
|
|
|
const (
|
2017-12-22 13:48:36 +01:00
|
|
|
VERSION = "v0.3.0"
|
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
|
2017-12-01 23:52:25 +01:00
|
|
|
flgDebug bool
|
2016-10-09 18:37:00 +02:00
|
|
|
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
|
|
|
|
2017-12-01 23:52:25 +01:00
|
|
|
flag.BoolVar(
|
|
|
|
&flgDebug,
|
|
|
|
"debug",
|
|
|
|
false,
|
|
|
|
"turn on debugging",
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
2017-07-15 15:57:59 +02:00
|
|
|
// Create custom event stream for termui because
|
|
|
|
// termui's one has data race conditions with its
|
|
|
|
// event handling. We're circumventing it here until
|
2017-07-30 15:23:47 +02:00
|
|
|
// it has been fixed.
|
2017-07-15 15:57:59 +02:00
|
|
|
customEvtStream := &termui.EvtStream{
|
|
|
|
Handlers: make(map[string]func(termui.Event)),
|
|
|
|
}
|
|
|
|
termui.DefaultEvtStream = customEvtStream
|
|
|
|
|
2016-09-25 22:34:02 +02:00
|
|
|
// Create context
|
2017-12-01 23:52:25 +01:00
|
|
|
ctx, err := context.CreateAppContext(flgConfig, flgDebug)
|
2017-08-04 10:22:42 +02:00
|
|
|
if err != nil {
|
|
|
|
termbox.Close()
|
|
|
|
log.Println(err)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2016-09-11 17:55:19 +02:00
|
|
|
|
2016-09-25 22:34:02 +02:00
|
|
|
// Register handlers
|
2016-09-11 17:55:19 +02:00
|
|
|
handlers.RegisterEventHandlers(ctx)
|
|
|
|
|
|
|
|
termui.Loop()
|
|
|
|
}
|