-
Notifications
You must be signed in to change notification settings - Fork 24
/
refresh.go
107 lines (88 loc) · 2.78 KB
/
refresh.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
package pods
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/containers/podman-tui/ui/style"
"github.com/containers/podman-tui/ui/utils"
"github.com/docker/go-units"
"github.com/rivo/tview"
)
func (pods *Pods) refresh() {
pods.table.Clear()
expand := 1
alignment := tview.AlignLeft
for i := 0; i < len(pods.headers); i++ {
pods.table.SetCell(0, i,
tview.NewTableCell(fmt.Sprintf("[::b]%s", strings.ToUpper(pods.headers[i]))). //nolint:perfsprint
SetExpansion(expand).
SetBackgroundColor(style.PageHeaderBgColor).
SetTextColor(style.PageHeaderFgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
}
rowIndex := 1
podList := pods.getData()
pods.table.SetTitle(fmt.Sprintf("[::b]%s[%d]", strings.ToUpper(pods.title), len(podList)))
for i := 0; i < len(podList); i++ {
podID := podList[i].Id
podID = podID[0:utils.IDLength]
podName := podList[i].Name
podStatus := podList[i].Status
podCreated := units.HumanDuration(time.Since(podList[i].Created)) + " ago"
podInfraID := podList[i].InfraId
if len(podInfraID) > utils.IDLength {
podInfraID = podInfraID[0:utils.IDLength]
}
podNumCtn := strconv.Itoa(len(podList[i].Containers))
cellTextColor := style.FgColor
switch strings.ToLower(podStatus) {
case "running":
podStatus = fmt.Sprintf("[green::]%s[-::] %s", "\u25B2", podStatus)
cellTextColor = style.RunningStatusFgColor
case "paused":
podStatus = fmt.Sprintf("[red::]%s[-::] %s", "\u25BC", podStatus)
cellTextColor = style.PausedStatusFgColor
default:
podStatus = fmt.Sprintf("[red::]%s[-::] %s", "\u25BC", podStatus)
}
// id column
pods.table.SetCell(rowIndex, viewPodIDColIndex,
tview.NewTableCell(podID).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
// name column
pods.table.SetCell(rowIndex, viewPodNameColIndex,
tview.NewTableCell(podName).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
// status column
pods.table.SetCell(rowIndex, viewPodStatusColIndex,
tview.NewTableCell(podStatus).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
// created column
pods.table.SetCell(rowIndex, viewPodCreatedColIndex,
tview.NewTableCell(podCreated).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
// infra id at column
pods.table.SetCell(rowIndex, viewPodInfraIDColIndex,
tview.NewTableCell(podInfraID).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
// # of container column
pods.table.SetCell(rowIndex, viewPodContainersColIndex,
tview.NewTableCell(podNumCtn).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
rowIndex++
}
}