mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
use GridBufferer as rows in CompactGrid
This commit is contained in:
parent
3bb48e91ae
commit
1dd5e53b37
@ -4,51 +4,36 @@ import (
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
var header = NewCompactHeader()
|
||||
|
||||
type CompactGrid struct {
|
||||
ui.GridBufferer
|
||||
Rows []*Compact // rows to render
|
||||
Rows []ui.GridBufferer
|
||||
X, Y int
|
||||
Width int
|
||||
Height int
|
||||
header *CompactHeader
|
||||
cursorID string
|
||||
}
|
||||
|
||||
func NewCompactGrid() *CompactGrid {
|
||||
return &CompactGrid{
|
||||
header: NewCompactHeader(),
|
||||
}
|
||||
return &CompactGrid{}
|
||||
}
|
||||
|
||||
func (cg *CompactGrid) Align() {
|
||||
// update header y pos
|
||||
if cg.header.Y != cg.Y {
|
||||
cg.header.SetY(cg.Y)
|
||||
}
|
||||
|
||||
// update row y pos recursively
|
||||
y := cg.Y + 1
|
||||
y := cg.Y
|
||||
for _, r := range cg.Rows {
|
||||
if r.Y != y {
|
||||
r.SetY(y)
|
||||
}
|
||||
y += r.Height
|
||||
}
|
||||
|
||||
// update header width
|
||||
if cg.header.Width != cg.Width {
|
||||
cg.header.SetWidth(cg.Width)
|
||||
r.SetY(y)
|
||||
y += r.GetHeight()
|
||||
}
|
||||
|
||||
// update row width recursively
|
||||
for _, r := range cg.Rows {
|
||||
if r.Width != cg.Width {
|
||||
r.SetWidth(cg.Width)
|
||||
}
|
||||
r.SetWidth(cg.Width)
|
||||
}
|
||||
}
|
||||
|
||||
func (cg *CompactGrid) Clear() { cg.Rows = []*Compact{} }
|
||||
func (cg *CompactGrid) Clear() { cg.Rows = []ui.GridBufferer{header} }
|
||||
func (cg *CompactGrid) GetHeight() int { return len(cg.Rows) }
|
||||
func (cg *CompactGrid) SetX(x int) { cg.X = x }
|
||||
func (cg *CompactGrid) SetY(y int) { cg.Y = y }
|
||||
@ -56,14 +41,13 @@ func (cg *CompactGrid) SetWidth(w int) { cg.Width = w }
|
||||
|
||||
func (cg *CompactGrid) Buffer() ui.Buffer {
|
||||
buf := ui.NewBuffer()
|
||||
buf.Merge(cg.header.Buffer())
|
||||
for _, r := range cg.Rows {
|
||||
buf.Merge(r.Buffer())
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
func (cg *CompactGrid) AddRows(rows ...*Compact) {
|
||||
func (cg *CompactGrid) AddRows(rows ...ui.GridBufferer) {
|
||||
for _, r := range rows {
|
||||
cg.Rows = append(cg.Rows, r)
|
||||
}
|
||||
|
@ -13,15 +13,19 @@ type CompactHeader struct {
|
||||
|
||||
func NewCompactHeader() *CompactHeader {
|
||||
fields := []string{"", "NAME", "CID", "CPU", "MEM", "NET RX/TX"}
|
||||
header := &CompactHeader{}
|
||||
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 := 1
|
||||
x := c.X
|
||||
autoWidth := calcWidth(w, 5)
|
||||
for n, col := range c.pars {
|
||||
// set status column to static width
|
||||
@ -38,6 +42,10 @@ func (c *CompactHeader) SetWidth(w int) {
|
||||
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)
|
||||
|
@ -32,6 +32,7 @@ func NewCompact(id string) *Compact {
|
||||
Cpu: NewGaugeCol(),
|
||||
Memory: NewGaugeCol(),
|
||||
Net: NewTextCol("-"),
|
||||
X: 1,
|
||||
Height: 1,
|
||||
}
|
||||
return row
|
||||
@ -58,7 +59,18 @@ func (row *Compact) Reset() {
|
||||
row.Net.Reset()
|
||||
}
|
||||
|
||||
func (row *Compact) GetHeight() int {
|
||||
return row.Height
|
||||
}
|
||||
|
||||
func (row *Compact) SetX(x int) {
|
||||
row.X = x
|
||||
}
|
||||
|
||||
func (row *Compact) SetY(y int) {
|
||||
if y == row.Y {
|
||||
return
|
||||
}
|
||||
for _, col := range row.all() {
|
||||
col.SetY(y)
|
||||
}
|
||||
@ -66,7 +78,10 @@ func (row *Compact) SetY(y int) {
|
||||
}
|
||||
|
||||
func (row *Compact) SetWidth(width int) {
|
||||
x := 1
|
||||
if width == row.Width {
|
||||
return
|
||||
}
|
||||
x := row.X
|
||||
autoWidth := calcWidth(width, 5)
|
||||
for n, col := range row.all() {
|
||||
// set status column to static width
|
||||
|
Loading…
Reference in New Issue
Block a user