-
Notifications
You must be signed in to change notification settings - Fork 24
/
refresh.go
116 lines (96 loc) · 3.11 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
108
109
110
111
112
113
114
115
116
package containers
import (
"fmt"
"strings"
"time"
"github.com/containers/podman-tui/ui/style"
"github.com/containers/podman-tui/ui/utils"
"github.com/docker/go-units"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
func (cnt *Containers) refresh() {
cnt.table.Clear()
expand := 1
alignment := tview.AlignLeft
for i := 0; i < len(cnt.headers); i++ {
cnt.table.SetCell(0, i,
tview.NewTableCell(fmt.Sprintf("[::b]%s", strings.ToUpper(cnt.headers[i]))). //nolint:perfsprint
SetExpansion(expand).
SetBackgroundColor(style.PageHeaderBgColor).
SetTextColor(style.PageHeaderFgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
}
rowIndex := 1
cntList := cnt.getData()
cnt.table.SetTitle(fmt.Sprintf("[::b]%s[%d]", strings.ToUpper(cnt.title), len(cntList)))
for i := 0; i < len(cntList); i++ {
cntID := cntList[i].ID
if len(cntID) > utils.IDLength {
cntID = cntID[:utils.IDLength]
}
cntImage := cntList[i].Image
cntPodName := cntList[i].PodName
cntCreated := units.HumanDuration(time.Since(cntList[i].Created)) + " ago"
cntStatus := conReporter{cntList[i]}.status()
cntPorts := conReporter{cntList[i]}.ports()
cntNames := conReporter{cntList[i]}.names()
var cellTextColor tcell.Color
cntShortStatus := strings.Split(strings.ToLower(cntStatus), " ")[0]
switch cntShortStatus {
case "up":
cntStatus = fmt.Sprintf("[green::]%s[-::] %s", "\u25B2", cntStatus)
cellTextColor = style.RunningStatusFgColor
case "paused":
cntStatus = fmt.Sprintf("[red::]%s[-::] %s", "\u25BC", cntStatus)
cellTextColor = style.PausedStatusFgColor
default:
cntStatus = fmt.Sprintf("[red::]%s[-::] %s", "\u25BC", cntStatus)
cellTextColor = style.FgColor
}
// id name column
cnt.table.SetCell(rowIndex, viewContainersIDColIndex,
tview.NewTableCell(cntID).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
// image name column
cnt.table.SetCell(rowIndex, viewContainersImageColIndex,
tview.NewTableCell(cntImage).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
// pod column
cnt.table.SetCell(rowIndex, viewContainersPodColIndex,
tview.NewTableCell(cntPodName).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
// created at column
cnt.table.SetCell(rowIndex, viewContainersCreatedAtColIndex,
tview.NewTableCell(cntCreated).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
// status column
cnt.table.SetCell(rowIndex, viewContainersStatusColIndex,
tview.NewTableCell(cntStatus).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
// names column
cnt.table.SetCell(rowIndex, viewContainersNamesColIndex,
tview.NewTableCell(cntNames).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
// ports column
cnt.table.SetCell(rowIndex, viewContainersPortsColIndex,
tview.NewTableCell(cntPorts).
SetTextColor(cellTextColor).
SetExpansion(expand).
SetAlign(alignment))
rowIndex++
}
}