@@ -34,6 +34,9 @@ import (
34
34
"github.com/gravitational/teleport/api/constants"
35
35
)
36
36
37
+ // topModel is a [tea.Model] implementation which
38
+ // displays various tabs and content displayed by
39
+ // the tctl top command.
37
40
type topModel struct {
38
41
width int
39
42
height int
@@ -52,6 +55,9 @@ func newTopModel(refreshInterval time.Duration, clt *roundtrip.Client) *topModel
52
55
}
53
56
}
54
57
58
+ // refresh pulls metrics from Teleport and builds
59
+ // a [Report] according to the configured refresh
60
+ // interval.
55
61
func (m * topModel ) refresh () tea.Cmd {
56
62
return func () tea.Msg {
57
63
if m .report != nil {
@@ -75,6 +81,8 @@ func (m *topModel) Init() tea.Cmd {
75
81
return m .refresh ()
76
82
}
77
83
84
+ // Update processes messages in order to updated the
85
+ // view based on user input and new metrics data.
78
86
func (m * topModel ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
79
87
switch msg := msg .(type ) {
80
88
case tea.WindowSizeMsg :
@@ -105,6 +113,8 @@ func (m *topModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
105
113
return m , nil
106
114
}
107
115
116
+ // View formats the metrics and draws them to
117
+ // the screen.
108
118
func (m * topModel ) View () string {
109
119
availableHeight := m .height
110
120
header := headerView (m .selected , m .width )
@@ -125,6 +135,9 @@ func (m *topModel) View() string {
125
135
)
126
136
}
127
137
138
+ // headerView generates the tab bar displayed at
139
+ // the top of the screen. The selectedTab will be
140
+ // rendered a different color to indicate as such.
128
141
func headerView (selectedTab int , width int ) string {
129
142
tabs := tabView (selectedTab )
130
143
@@ -138,6 +151,8 @@ func headerView(selectedTab int, width int) string {
138
151
return tabs + lipgloss .NewStyle ().Render (filler ) + "\n " + strings .Repeat ("‾" , width )
139
152
}
140
153
154
+ // footerView generates the help text displayed at the
155
+ // bottom of the screen.
141
156
func (m * topModel ) footerView () string {
142
157
underscore := lipgloss .NewStyle ().Underline (true ).Render (" " )
143
158
underline := strings .Repeat (underscore , m .width )
@@ -173,6 +188,8 @@ func (m *topModel) footerView() string {
173
188
statusBarStyle .Render (right )
174
189
}
175
190
191
+ // contentView generates the appropriate content
192
+ // based on which tab is selected.
176
193
func (m * topModel ) contentView () string {
177
194
if m .report == nil {
178
195
return ""
@@ -192,6 +209,7 @@ func (m *topModel) contentView() string {
192
209
}
193
210
}
194
211
212
+ // renderCommon generates the view for the cluster stats tab.
195
213
func renderCommon (report * Report , width int ) string {
196
214
columnWidth := width / 2
197
215
@@ -294,6 +312,7 @@ func renderCommon(report *Report, width int) string {
294
312
)
295
313
}
296
314
315
+ // renderBackend generates the view for the backend stats tab.
297
316
func renderBackend (report * Report , height , width int ) string {
298
317
latencyWidth := width / 3
299
318
requestsWidth := width * 2 / 3
@@ -326,6 +345,7 @@ func renderBackend(report *Report, height, width int) string {
326
345
)
327
346
}
328
347
348
+ // renderCache generates the view for the cache stats tab.
329
349
func renderCache (report * Report , height , width int ) string {
330
350
latencyWidth := width / 3
331
351
requestsWidth := width * 2 / 3
@@ -359,6 +379,7 @@ func renderCache(report *Report, height, width int) string {
359
379
)
360
380
}
361
381
382
+ // renderWatcher generates the view for the watcher stats tab.
362
383
func renderWatcher (report * Report , height , width int ) string {
363
384
graphWidth := width * 40 / 100
364
385
graphHeight := height / 3
@@ -412,6 +433,7 @@ func renderWatcher(report *Report, height, width int) string {
412
433
)
413
434
}
414
435
436
+ // tabView renders the tabbed content in the header.
415
437
func tabView (selectedTab int ) string {
416
438
output := lipgloss .NewStyle ().
417
439
Underline (true ).
0 commit comments