-
Notifications
You must be signed in to change notification settings - Fork 534
/
Copy pathheader.go
70 lines (61 loc) · 1.19 KB
/
header.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
package compact
import (
ui "github.com/gizak/termui"
)
type CompactHeader struct {
X, Y int
Width int
Height int
pars []*ui.Par
}
func NewCompactHeader() *CompactHeader {
fields := []string{"", "NAME", "CID", "CPU", "MEM", "NET RX/TX", "IO R/W", "PIDS", "UPTIME"}
ch := &CompactHeader{}
ch.Height = 2
for _, f := range fields {
ch.addFieldPar(f)
}
return ch
}
func (ch *CompactHeader) GetHeight() int {
return ch.Height
}
func (ch *CompactHeader) SetWidth(w int) {
x := ch.X
autoWidth := calcWidth(w)
for n, col := range ch.pars {
// set column to static width
if colWidths[n] != 0 {
col.SetX(x)
col.SetWidth(colWidths[n])
x += colWidths[n]
continue
}
col.SetX(x)
col.SetWidth(autoWidth)
x += autoWidth + colSpacing
}
ch.Width = w
}
func (ch *CompactHeader) SetX(x int) {
ch.X = x
}
func (ch *CompactHeader) SetY(y int) {
for _, p := range ch.pars {
p.SetY(y)
}
ch.Y = y
}
func (ch *CompactHeader) Buffer() ui.Buffer {
buf := ui.NewBuffer()
for _, p := range ch.pars {
buf.Merge(p.Buffer())
}
return buf
}
func (ch *CompactHeader) addFieldPar(s string) {
p := ui.NewPar(s)
p.Height = ch.Height
p.Border = false
ch.pars = append(ch.pars, p)
}