-
Notifications
You must be signed in to change notification settings - Fork 6
/
client.go
57 lines (46 loc) · 1.01 KB
/
client.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
package client
import (
"errors"
"github.com/pterm/pterm"
"github.com/szpnygo/gtc/client/layout"
"github.com/szpnygo/gtc/client/server"
"github.com/szpnygo/gtc/gocui"
)
type GTCClient struct {
g *gocui.Gui
l *layout.LayoutManager
s *server.ClientServer
api string
}
func NewGTCClient(api string) *GTCClient {
return >CClient{
api: api,
}
}
func (gtc *GTCClient) Run() error {
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
pterm.Error.Println("Failed to create GUI", err)
return err
}
defer g.Close()
gtc.g = g
//config
g.Mouse = false
g.Cursor = true
g.InputEsc = true
gtc.l = layout.NewLayoutManager(g, func(g *gocui.Gui, v *gocui.View) error {
if gtc.s != nil {
gtc.s.Stop()
}
return gocui.ErrQuit
})
gtc.s = server.NewClientServer(gtc.api, gtc.l)
go gtc.s.Run()
g.SetManagerFunc(gtc.l.LoginLayout)
gtc.l.KeyBinding(g)
if err := g.MainLoop(); err != nil && errors.Is(err, gocui.ErrQuit) {
pterm.Error.Println("Failed to start main loop", err)
}
return nil
}