mirror of
https://github.com/bcicen/ctop.git
synced 2025-11-17 16:30:37 +01:00
72 lines
1.2 KiB
Go
72 lines
1.2 KiB
Go
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"}
|
|
header := &CompactHeader{Height: 2}
|
|
for _, f := range fields {
|
|
header.pars = append(header.pars, headerPar(f))
|
|
}
|
|
return header
|
|
}
|
|
|
|
func (c *CompactHeader) GetHeight() int {
|
|
return c.Height
|
|
}
|
|
|
|
func (c *CompactHeader) SetWidth(w int) {
|
|
x := c.X
|
|
autoWidth := calcWidth(w, 5)
|
|
for n, col := range c.pars {
|
|
// set status column to static width
|
|
if n == 0 {
|
|
col.SetX(x)
|
|
col.SetWidth(statusWidth)
|
|
x += statusWidth
|
|
continue
|
|
}
|
|
col.SetX(x)
|
|
col.SetWidth(autoWidth)
|
|
x += autoWidth + colSpacing
|
|
}
|
|
c.Width = w
|
|
}
|
|
|
|
func (c *CompactHeader) SetX(x int) {
|
|
c.X = x
|
|
}
|
|
|
|
func (c *CompactHeader) SetY(y int) {
|
|
for _, p := range c.pars {
|
|
p.SetY(y)
|
|
}
|
|
c.Y = y
|
|
}
|
|
|
|
func (c *CompactHeader) Buffer() ui.Buffer {
|
|
buf := ui.NewBuffer()
|
|
for _, p := range c.pars {
|
|
buf.Merge(p.Buffer())
|
|
}
|
|
return buf
|
|
}
|
|
|
|
func headerPar(s string) *ui.Par {
|
|
p := ui.NewPar(s)
|
|
p.Y = 2
|
|
p.Height = 2
|
|
p.Width = 20
|
|
p.Border = false
|
|
return p
|
|
}
|