-
Notifications
You must be signed in to change notification settings - Fork 4
/
actions.go
160 lines (129 loc) · 3.29 KB
/
actions.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
package main
import (
"github.com/jroimartin/gocui"
)
var DEBUG_DISPLAYED bool = false
var NAMESPACES_DISPLAYED bool = false
// Global action: Quit
func actionGlobalQuit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}
// Global action: Toggle debug
func actionGlobalToggleViewDebug(g *gocui.Gui, v *gocui.View) error {
vn := "debug"
if !DEBUG_DISPLAYED {
debug(g, "Action: Display debug popup")
g.SetViewOnTop(vn)
g.SetCurrentView(vn)
} else {
debug(g, "Action: Hide debug popup")
g.SetViewOnBottom(vn)
g.SetCurrentView("pods")
}
DEBUG_DISPLAYED = !DEBUG_DISPLAYED
return nil
}
// View namespaces: Toggle display
func actionGlobalToggleViewNamespaces(g *gocui.Gui, v *gocui.View) error {
vn := "namespaces"
if !NAMESPACES_DISPLAYED {
debug(g, "Action: Display namespaces popup")
g.SetViewOnTop(vn)
g.SetCurrentView(vn)
changeStatusContext(g, "SE")
} else {
debug(g, "Action: Hide namespaces popup")
g.SetViewOnBottom(vn)
g.SetCurrentView("pods")
changeStatusContext(g, "D")
}
NAMESPACES_DISPLAYED = !NAMESPACES_DISPLAYED
return nil
}
// View pods: Up
func actionViewPodsUp(g *gocui.Gui, v *gocui.View) error {
moveViewCursorUp(g, v, 2)
debug(g, "Select up in pods view")
return nil
}
// View pods: Down
func actionViewPodsDown(g *gocui.Gui, v *gocui.View) error {
moveViewCursorDown(g, v, false)
debug(g, "Select down in pods view")
return nil
}
// View pods: Delete
func actionViewPodsDelete(g *gocui.Gui, v *gocui.View) error {
p, err := getSelectedPod(g)
if err != nil {
return err
}
if err := deletePod(p); err != nil {
return err
}
debug(g, "Delete pod: "+p)
displayConfirmation(g, p+" pod deleted")
go viewPodsRefreshList(g)
return nil
}
// View pods: Logs
func actionViewPodsLogs(g *gocui.Gui, v *gocui.View) error {
LOG_MOD = "pod"
err := showViewPodsLogs(g)
changeStatusContext(g, "SL")
return err
}
// View pod logs: Up
func actionViewPodsLogsUp(g *gocui.Gui, v *gocui.View) error {
vLc, err := g.View("logs-containers")
if err != nil {
return err
}
moveViewCursorUp(g, vLc, 0)
refreshPodsLogs(g)
debug(g, "Select up in logs view")
return nil
}
// View pod logs: Down
func actionViewPodsLogsDown(g *gocui.Gui, v *gocui.View) error {
vLc, err := g.View("logs-containers")
if err != nil {
return err
}
moveViewCursorDown(g, vLc, false)
refreshPodsLogs(g)
debug(g, "Select down in logs view")
return nil
}
// View logs: Hide
func actionViewPodsLogsHide(g *gocui.Gui, v *gocui.View) error {
g.SetViewOnBottom("logs")
g.SetViewOnBottom("logs-containers")
g.SetCurrentView("pods")
v.Clear()
changeStatusContext(g, "D")
debug(g, "Action: Hide view logs)")
return nil
}
// View namespaces: Up
func actionViewNamespacesUp(g *gocui.Gui, v *gocui.View) error {
moveViewCursorUp(g, v, 0)
debug(g, "Select up in namespaces view")
return nil
}
// View namespaces: Down
func actionViewNamespacesDown(g *gocui.Gui, v *gocui.View) error {
moveViewCursorDown(g, v, false)
debug(g, "Select down in namespaces view")
return nil
}
// Namespace: Choose
func actionViewNamespacesSelect(g *gocui.Gui, v *gocui.View) error {
line, err := getViewLine(g, v)
debug(g, "Select namespace: "+line)
NAMESPACE = line
go viewPodsRefreshList(g)
actionGlobalToggleViewNamespaces(g, v)
displayConfirmation(g, line+" namespace selected")
return err
}