-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
76 lines (59 loc) · 1.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"flag"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/termoose/irccloud/config"
"github.com/termoose/irccloud/events"
"github.com/termoose/irccloud/requests"
"github.com/termoose/irccloud/ui"
"log"
)
func main() {
configFilename := flag.String("c", "", "path to config file")
flag.Parse()
// Set this, so we don't overwrite the default terminal
// background color
tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault
var conf config.Data
if isFlagSet("c") {
conf = config.ParseCustom(*configFilename)
} else {
conf = config.Parse()
}
sessionData, err := requests.GetSessionToken(conf.Username, conf.Password)
if err != nil {
log.Println(err)
return
}
wsConn := requests.NewConnection(sessionData)
view := ui.NewView(wsConn, &conf)
defer func() {
current := view.GetCurrentChannel()
config.WriteLatestChannel(conf, current)
view.Stop()
}()
eventHandler := events.NewHandler(sessionData.APIHost,
sessionData.Session, view)
go func() {
for {
msg, err := wsConn.ReadMessage()
if err != nil {
view.Stop()
log.Print(err)
return
}
eventHandler.Enqueue(msg)
}
}()
view.Start()
}
func isFlagSet(name string) bool {
found := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})
return found
}