-
Notifications
You must be signed in to change notification settings - Fork 24
/
data.go
60 lines (49 loc) · 1.43 KB
/
data.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
package pods
import (
"fmt"
"strings"
ppods "github.com/containers/podman-tui/pdcs/pods"
"github.com/containers/podman-tui/ui/style"
"github.com/containers/podman/v5/pkg/domain/entities"
"github.com/rivo/tview"
"github.com/rs/zerolog/log"
)
// UpdateData retrieves pods list data.
func (pods *Pods) UpdateData() {
podList, err := ppods.List()
if err != nil {
log.Error().Msgf("view: pods update %v", err)
pods.errorDialog.SetText(fmt.Sprintf("%v", err))
pods.errorDialog.Display()
return
}
pods.podsList.mu.Lock()
pods.podsList.report = podList
pods.podsList.mu.Unlock()
}
func (pods *Pods) getData() []*entities.ListPodsReport {
pods.podsList.mu.Lock()
data := pods.podsList.report
pods.podsList.mu.Unlock()
return data
}
// ClearData clears table data.
func (pods *Pods) ClearData() { //nolint:stylecheck
pods.podsList.mu.Lock()
pods.podsList.report = nil
pods.podsList.mu.Unlock()
pods.table.Clear()
expand := 1
fgColor := style.PageHeaderFgColor
bgColor := style.PageHeaderBgColor
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(bgColor).
SetTextColor(fgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
}
pods.table.SetTitle(fmt.Sprintf("[::b]%s[0]", strings.ToUpper(pods.title)))
}