()
| 182 | } |
| 183 | |
| 184 | func (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). |
no test coverage detected