-
Notifications
You must be signed in to change notification settings - Fork 3
/
cui_funcs.go
186 lines (148 loc) · 3.11 KB
/
cui_funcs.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package main
import (
"fmt"
"io"
"log"
"github.com/jroimartin/gocui"
)
func nextView(g *gocui.Gui, v *gocui.View) error {
if v == nil || v.Name() == ServersView {
_, err := g.SetCurrentView(FXServerCmdView)
return err
}
_, err := g.SetCurrentView(ServersView)
return err
}
func cursorDown(g *gocui.Gui, v *gocui.View) error {
if v != nil {
cx, cy := v.Cursor()
if err := v.SetCursor(cx, cy+1); err != nil {
ox, oy := v.Origin()
if err := v.SetOrigin(ox, oy+1); err != nil {
return err
}
}
}
return nil
}
func cursorUp(g *gocui.Gui, v *gocui.View) error {
if v != nil {
ox, oy := v.Origin()
cx, cy := v.Cursor()
if err := v.SetCursor(cx, cy-1); err != nil && oy > 0 {
if err := v.SetOrigin(ox, oy-1); err != nil {
return err
}
}
}
return nil
}
func onSideEnter(g *gocui.Gui, v *gocui.View) error {
_, cy := v.Cursor()
profile, err := v.Line(cy)
if err != nil {
return err
}
go func() {
g.Update(func(g *gocui.Gui) error {
v, err := g.View(StatusView)
if err != nil {
return err
}
v.Clear()
fmt.Fprintln(v, "Server running")
v.FgColor = gocui.ColorGreen
return nil
})
}()
startFxServer(profile, g)
return nil
}
func executeCommand(g *gocui.Gui, v *gocui.View) error {
var err error
v.Rewind()
if err != nil {
log.Fatal(err)
}
if v.Buffer() == "quit" {
io.WriteString(Writer, v.Buffer())
v.Clear()
vM, _ := g.View(FXServerView)
vM.Clear()
g.Update(func(g *gocui.Gui) error {
return nil
})
g.SetCurrentView(ServersView)
return nil
}
if v.Buffer() != "" {
io.WriteString(Writer, v.Buffer())
}
v.Clear()
v.SetCursor(0, 0)
if err != nil {
return err
}
return nil
}
func saveNewProfile(g *gocui.Gui, v *gocui.View) error {
var err error
v.Rewind()
if err != nil {
log.Fatal(err)
}
if v.Buffer() != "" {
ServerPath = v.Buffer()
err = g.DeleteView("profile_path")
if err != nil {
return err
}
}
if _, err := g.SetCurrentView(ServersView); err != nil {
return err
}
return nil
}
func newProfileNameView(g *gocui.Gui, v *gocui.View) error {
maxX, maxY := g.Size()
if vp_n, err := g.SetView("profile_name", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil {
if err != gocui.ErrUnknownView {
return err
}
vp_n.Title = "Add server name - Enter to continue | Abort with q "
vp_n.BgColor = gocui.ColorBlack
vp_n.Editable = true
}
if _, err := g.SetCurrentView("profile_name"); err != nil {
return err
}
return nil
}
func newProfilePathView(g *gocui.Gui, v *gocui.View) error {
var err error
v.Rewind()
if err != nil {
log.Fatal(err)
}
if v.Buffer() != "" {
ServerName = v.Buffer()
}
maxX, maxY := g.Size()
if vp_p, err := g.SetView("profile_path", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil {
if err != gocui.ErrUnknownView {
return err
}
vp_p.Title = "Add startup path - Enter to finish | Abort with q "
vp_p.BgColor = gocui.ColorBlack
vp_p.Editable = true
}
if _, err := g.SetCurrentView("profile_path"); err != nil {
return err
}
// delete profile_name view
err = g.DeleteView("profile_name")
if err != nil {
return err
}
return nil
}