MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / populateTable

Method populateTable

internal/ui/plugins/guestlist/view.go:184–273  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

182}
183
184func (v *guestListView) populateTable() {
185 v.table.Clear()
186 headers := []struct {
187 label string
188 align int
189 expansion int
190 }{
191 {"Guest", tview.AlignLeft, 2},
192 {"Type", tview.AlignLeft, 1},
193 {"Status", tview.AlignLeft, 1},
194 {"CPU", tview.AlignRight, 1},
195 {"Memory", tview.AlignLeft, 2},
196 {"Uptime", tview.AlignLeft, 1},
197 {"IP", tview.AlignLeft, 2},
198 {"Tags", tview.AlignLeft, 2},
199 {"Agent", tview.AlignLeft, 1},
200 }
201
202 for idx, header := range headers {
203 cell := tview.NewTableCell(header.label).
204 SetTextColor(theme.Colors.HeaderText).
205 SetSelectable(false).
206 SetAlign(header.align).
207 SetExpansion(header.expansion)
208 v.table.SetCell(0, idx, cell)
209 }
210
211 if len(v.rows) == 0 {
212 message := "No matching guests. Press 'a' to include stopped guests."
213 cell := tview.NewTableCell(message).
214 SetTextColor(theme.Colors.Warning).
215 SetSelectable(false).
216 SetAlign(tview.AlignCenter)
217 v.table.SetCell(1, 0, cell)
218 for col := 1; col < len(headers); col++ {
219 v.table.SetCell(1, col, tview.NewTableCell("").SetSelectable(false))
220 }
221
222 return
223 }
224
225 for i, row := range v.rows {
226 rowIdx := i + 1
227 v.table.SetCell(rowIdx, 0, tview.NewTableCell(formatGuestLabel(row)).
228 SetTextColor(theme.Colors.Primary).
229 SetAlign(tview.AlignLeft))
230
231 v.table.SetCell(rowIdx, 1, tview.NewTableCell(row.typeLabel).
232 SetTextColor(theme.Colors.Secondary))
233
234 statusText := formatStatusText(row.status)
235 statusColor := statusColorFor(row.status)
236 v.table.SetCell(rowIdx, 2, tview.NewTableCell(statusText).
237 SetTextColor(statusColor))
238
239 cpuText := fmt.Sprintf("%.1f%%", row.cpuPercent)
240 v.table.SetCell(rowIdx, 3, tview.NewTableCell(cpuText).
241 SetAlign(tview.AlignRight).

Callers 1

applyStateMethod · 0.95

Calls 9

GetUsageColorFunction · 0.92
FormatUptimeFunction · 0.92
formatGuestLabelFunction · 0.85
formatStatusTextFunction · 0.85
statusColorForFunction · 0.85
formatMemoryCellFunction · 0.85
agentStateCellFunction · 0.85
SetTextColorMethod · 0.80
ClearMethod · 0.65

Tested by

no test coverage detected