-
Notifications
You must be signed in to change notification settings - Fork 24
/
refresh.go
73 lines (59 loc) · 1.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
package volumes
import (
"fmt"
"strings"
"time"
"github.com/containers/podman-tui/ui/style"
"github.com/docker/go-units"
"github.com/rivo/tview"
)
const (
volsTableDriverColIndex = 0 + iota
volsTableNameColIndex
volsTableCreatedAtColIndex
volsTableMountPointColIndex
)
func (vols *Volumes) refresh() {
vols.table.Clear()
expand := 1
alignment := tview.AlignLeft
for i := 0; i < len(vols.headers); i++ {
vols.table.SetCell(0, i,
tview.NewTableCell(fmt.Sprintf("[::b]%s", strings.ToUpper(vols.headers[i]))). //nolint:perfsprint
SetExpansion(expand).
SetBackgroundColor(style.PageHeaderBgColor).
SetTextColor(style.PageHeaderFgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
}
rowIndex := 1
volList := vols.getData()
vols.table.SetTitle(fmt.Sprintf("[::b]%s[%d]", strings.ToUpper(vols.title), len(volList)))
for i := 0; i < len(volList); i++ {
volDriver := volList[i].Driver
volName := volList[i].Name
volCreatedAt := units.HumanDuration(time.Since(volList[i].CreatedAt)) + " ago"
volMountPoint := volList[i].Mountpoint
// driver name column
vols.table.SetCell(rowIndex, volsTableDriverColIndex,
tview.NewTableCell(volDriver).
SetExpansion(expand).
SetAlign(alignment))
// name column
vols.table.SetCell(rowIndex, volsTableNameColIndex,
tview.NewTableCell(volName).
SetExpansion(expand).
SetAlign(alignment))
// created at column
vols.table.SetCell(rowIndex, volsTableCreatedAtColIndex,
tview.NewTableCell(volCreatedAt).
SetExpansion(expand).
SetAlign(alignment))
// mount point at column
vols.table.SetCell(rowIndex, volsTableMountPointColIndex,
tview.NewTableCell(volMountPoint).
SetExpansion(expand).
SetAlign(alignment))
rowIndex++
}
}