mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package compact
|
|
|
|
import (
|
|
ui "github.com/gizak/termui"
|
|
)
|
|
|
|
var header = NewCompactHeader()
|
|
|
|
type CompactGrid struct {
|
|
ui.GridBufferer
|
|
Rows []ui.GridBufferer
|
|
X, Y int
|
|
Width int
|
|
Height int
|
|
cursorID string
|
|
}
|
|
|
|
func NewCompactGrid() *CompactGrid {
|
|
return &CompactGrid{}
|
|
}
|
|
|
|
func (cg *CompactGrid) Align() {
|
|
// update row y pos recursively
|
|
y := cg.Y
|
|
for _, r := range cg.Rows {
|
|
r.SetY(y)
|
|
y += r.GetHeight()
|
|
}
|
|
|
|
// update row width recursively
|
|
for _, r := range cg.Rows {
|
|
r.SetWidth(cg.Width)
|
|
}
|
|
}
|
|
|
|
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 }
|
|
func (cg *CompactGrid) SetWidth(w int) { cg.Width = w }
|
|
func (cg *CompactGrid) MaxRows() int { return ui.TermHeight() - header.Height - cg.Y }
|
|
|
|
func (cg *CompactGrid) Buffer() ui.Buffer {
|
|
buf := ui.NewBuffer()
|
|
for _, r := range cg.Rows {
|
|
buf.Merge(r.Buffer())
|
|
}
|
|
return buf
|
|
}
|
|
|
|
func (cg *CompactGrid) AddRows(rows ...ui.GridBufferer) {
|
|
for _, r := range rows {
|
|
cg.Rows = append(cg.Rows, r)
|
|
}
|
|
}
|