mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add pagination support for compact view
This commit is contained in:
@@ -8,11 +8,11 @@ var header = NewCompactHeader()
|
||||
|
||||
type CompactGrid struct {
|
||||
ui.GridBufferer
|
||||
Rows []ui.GridBufferer
|
||||
X, Y int
|
||||
Width int
|
||||
Height int
|
||||
cursorID string
|
||||
Rows []ui.GridBufferer
|
||||
X, Y int
|
||||
Width int
|
||||
Height int
|
||||
Offset int // starting row offset
|
||||
}
|
||||
|
||||
func NewCompactGrid() *CompactGrid {
|
||||
@@ -20,29 +20,31 @@ func NewCompactGrid() *CompactGrid {
|
||||
}
|
||||
|
||||
func (cg *CompactGrid) Align() {
|
||||
// update row y pos recursively
|
||||
// update row ypos, width recursively
|
||||
y := cg.Y
|
||||
for _, r := range cg.Rows {
|
||||
for _, r := range cg.pageRows() {
|
||||
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) Clear() { cg.Rows = []ui.GridBufferer{} }
|
||||
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) pageRows() (rows []ui.GridBufferer) {
|
||||
rows = append(rows, header)
|
||||
rows = append(rows, cg.Rows[cg.Offset:]...)
|
||||
return rows
|
||||
}
|
||||
|
||||
func (cg *CompactGrid) Buffer() ui.Buffer {
|
||||
buf := ui.NewBuffer()
|
||||
for _, r := range cg.Rows {
|
||||
for _, r := range cg.pageRows() {
|
||||
buf.Merge(r.Buffer())
|
||||
}
|
||||
return buf
|
||||
|
||||
Reference in New Issue
Block a user