2017-02-26 22:04:24 +00:00
|
|
|
package compact
|
|
|
|
|
|
|
|
import (
|
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CompactHeader struct {
|
2017-02-26 22:55:45 +00:00
|
|
|
X, Y int
|
|
|
|
Width int
|
|
|
|
Height int
|
2017-03-06 00:15:32 +00:00
|
|
|
pars []*ui.Par
|
2017-02-26 22:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewCompactHeader() *CompactHeader {
|
|
|
|
fields := []string{"", "NAME", "CID", "CPU", "MEM", "NET RX/TX"}
|
|
|
|
header := &CompactHeader{}
|
|
|
|
for _, f := range fields {
|
2017-03-06 00:15:32 +00:00
|
|
|
header.pars = append(header.pars, headerPar(f))
|
2017-02-26 22:04:24 +00:00
|
|
|
}
|
|
|
|
return header
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CompactHeader) SetWidth(w int) {
|
|
|
|
x := 1
|
|
|
|
autoWidth := calcWidth(w, 5)
|
|
|
|
for n, col := range c.pars {
|
2017-03-06 00:15:32 +00:00
|
|
|
// set status column to static width
|
2017-02-26 22:04:24 +00:00
|
|
|
if n == 0 {
|
|
|
|
col.SetX(x)
|
|
|
|
col.SetWidth(statusWidth)
|
|
|
|
x += statusWidth
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
col.SetX(x)
|
|
|
|
col.SetWidth(autoWidth)
|
|
|
|
x += autoWidth + colSpacing
|
|
|
|
}
|
2017-02-26 22:55:45 +00:00
|
|
|
c.Width = w
|
2017-02-26 22:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CompactHeader) SetY(y int) {
|
|
|
|
for _, p := range c.pars {
|
|
|
|
p.SetY(y)
|
|
|
|
}
|
2017-02-26 22:55:45 +00:00
|
|
|
c.Y = y
|
2017-02-26 22:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CompactHeader) Buffer() ui.Buffer {
|
|
|
|
buf := ui.NewBuffer()
|
|
|
|
for _, p := range c.pars {
|
|
|
|
buf.Merge(p.Buffer())
|
|
|
|
}
|
|
|
|
return buf
|
|
|
|
}
|
2017-03-06 00:15:32 +00:00
|
|
|
|
|
|
|
func headerPar(s string) *ui.Par {
|
|
|
|
p := ui.NewPar(s)
|
|
|
|
p.Y = 2
|
|
|
|
p.Height = 2
|
|
|
|
p.Width = 20
|
|
|
|
p.Border = false
|
|
|
|
return p
|
|
|
|
}
|