mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
restructure compact widgets
This commit is contained in:
@@ -5,28 +5,26 @@ import (
|
||||
)
|
||||
|
||||
type CompactHeader struct {
|
||||
pars []*ui.Par
|
||||
X, Y int
|
||||
Width int
|
||||
Height int
|
||||
pars []*ui.Par
|
||||
}
|
||||
|
||||
func NewCompactHeader() *CompactHeader {
|
||||
fields := []string{"", "NAME", "CID", "CPU", "MEM", "NET RX/TX"}
|
||||
header := &CompactHeader{}
|
||||
for _, f := range fields {
|
||||
header.pars = append(header.pars, slimHeaderPar(f))
|
||||
header.pars = append(header.pars, headerPar(f))
|
||||
}
|
||||
return header
|
||||
}
|
||||
|
||||
func (c *CompactHeader) SetWidth(w int) {
|
||||
if w == c.Width {
|
||||
return
|
||||
}
|
||||
x := 1
|
||||
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)
|
||||
@@ -41,9 +39,6 @@ func (c *CompactHeader) SetWidth(w int) {
|
||||
}
|
||||
|
||||
func (c *CompactHeader) SetY(y int) {
|
||||
if y == c.Y {
|
||||
return
|
||||
}
|
||||
for _, p := range c.pars {
|
||||
p.SetY(y)
|
||||
}
|
||||
@@ -57,3 +52,12 @@ func (c *CompactHeader) Buffer() ui.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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user