mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
move field header into CompactGrid, add Align() method
This commit is contained in:
parent
b84e22fb90
commit
4709624b17
@ -131,11 +131,6 @@ func (cm *ContainerMap) UpdateLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
// Return number of containers/rows
|
||||
func (cm *ContainerMap) Len() uint {
|
||||
return uint(len(cm.containers))
|
||||
}
|
||||
|
||||
// Get a single container, by ID
|
||||
func (cm *ContainerMap) Get(id string) (*Container, bool) {
|
||||
for _, c := range cm.containers {
|
||||
|
35
grid.go
35
grid.go
@ -8,27 +8,25 @@ import (
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
var cGrid = &widgets.CompactGrid{}
|
||||
var cGrid = widgets.NewCompactGrid()
|
||||
|
||||
func maxRows() int {
|
||||
return ui.TermHeight() - 2 - cGrid.Y
|
||||
}
|
||||
|
||||
type Grid struct {
|
||||
cursorID string // id of currently selected container
|
||||
cmap *ContainerMap
|
||||
containers Containers // sorted slice of containers
|
||||
header *widgets.CTopHeader
|
||||
fieldHeader *widgets.CompactHeader
|
||||
cursorID string // id of currently selected container
|
||||
cmap *ContainerMap
|
||||
containers Containers // sorted slice of containers
|
||||
header *widgets.CTopHeader
|
||||
}
|
||||
|
||||
func NewGrid() *Grid {
|
||||
cmap := NewContainerMap()
|
||||
g := &Grid{
|
||||
cmap: cmap,
|
||||
containers: cmap.All(),
|
||||
header: widgets.NewCTopHeader(),
|
||||
fieldHeader: widgets.NewCompactHeader(),
|
||||
cmap: cmap,
|
||||
containers: cmap.All(),
|
||||
header: widgets.NewCTopHeader(),
|
||||
}
|
||||
return g
|
||||
}
|
||||
@ -88,7 +86,6 @@ func (g *Grid) cursorDown() {
|
||||
func (g *Grid) redrawRows() {
|
||||
// reinit body rows
|
||||
cGrid.Rows = []widgets.ContainerWidgets{}
|
||||
ui.Clear()
|
||||
|
||||
// build layout
|
||||
y := 1
|
||||
@ -98,10 +95,10 @@ func (g *Grid) redrawRows() {
|
||||
g.header.Render()
|
||||
y += g.header.Height()
|
||||
}
|
||||
cGrid.SetY(y)
|
||||
|
||||
var cursorVisible bool
|
||||
max := maxRows()
|
||||
y += 2 // for field header
|
||||
for n, c := range g.containers.Filter() {
|
||||
if n >= max {
|
||||
break
|
||||
@ -111,20 +108,16 @@ func (g *Grid) redrawRows() {
|
||||
cursorVisible = true
|
||||
}
|
||||
}
|
||||
cGrid.SetY(y)
|
||||
cGrid.SetWidth(ui.TermWidth())
|
||||
|
||||
//log.Infof("rows: %d", len(cGrid.Rows))
|
||||
//log.Infof("Width: %d", cGrid.Width)
|
||||
//log.Infof("Height: %d", cGrid.Height)
|
||||
//log.Infof("X: %d", cGrid.X)
|
||||
//log.Infof("Y: %d", cGrid.Y)
|
||||
|
||||
if !cursorVisible {
|
||||
g.cursorReset()
|
||||
}
|
||||
|
||||
ui.Render(g.fieldHeader)
|
||||
ui.Clear()
|
||||
if config.GetSwitchVal("enableHeader") {
|
||||
g.header.Render()
|
||||
}
|
||||
cGrid.Align()
|
||||
ui.Render(cGrid)
|
||||
}
|
||||
|
||||
|
@ -21,26 +21,37 @@ type CompactGrid struct {
|
||||
X, Y int
|
||||
Width int
|
||||
Height int
|
||||
header *CompactHeader
|
||||
}
|
||||
|
||||
func (c CompactGrid) SetX(x int) { c.X = x }
|
||||
func (c CompactGrid) SetY(y int) {
|
||||
c.Y = y
|
||||
func NewCompactGrid() *CompactGrid {
|
||||
return &CompactGrid{
|
||||
header: NewCompactHeader(),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CompactGrid) Align() {
|
||||
// Update y recursively
|
||||
c.header.SetY(c.Y)
|
||||
y := c.Y + 1
|
||||
for n, r := range c.Rows {
|
||||
log.Infof("row %d: y=%d", n, c.Y+n)
|
||||
r.SetY(c.Y + n)
|
||||
r.SetY(y + n)
|
||||
}
|
||||
}
|
||||
func (c CompactGrid) GetHeight() int { return len(c.Rows) }
|
||||
func (c CompactGrid) SetWidth(w int) {
|
||||
c.Width = w
|
||||
// Update width recursively
|
||||
c.header.SetWidth(c.Width)
|
||||
for _, r := range c.Rows {
|
||||
r.SetWidth(w)
|
||||
r.SetWidth(c.Width)
|
||||
}
|
||||
}
|
||||
|
||||
func (c CompactGrid) Buffer() ui.Buffer {
|
||||
func (c *CompactGrid) GetHeight() int { return len(c.Rows) }
|
||||
func (c *CompactGrid) SetX(x int) { c.X = x }
|
||||
func (c *CompactGrid) SetY(y int) { c.Y = y }
|
||||
func (c *CompactGrid) SetWidth(w int) { c.Width = w }
|
||||
|
||||
func (c *CompactGrid) Buffer() ui.Buffer {
|
||||
buf := ui.NewBuffer()
|
||||
buf.Merge(c.header.Buffer())
|
||||
for _, r := range c.Rows {
|
||||
buf.Merge(r.Buffer())
|
||||
}
|
||||
@ -74,6 +85,29 @@ func NewCompactHeader() *CompactHeader {
|
||||
return header
|
||||
}
|
||||
|
||||
func (c *CompactHeader) SetWidth(w int) {
|
||||
x := 1
|
||||
statusWidth := 3
|
||||
autoWidth := (w - statusWidth) / 5
|
||||
for n, col := range c.pars {
|
||||
if n == 0 {
|
||||
col.SetX(x)
|
||||
col.SetWidth(statusWidth)
|
||||
x += statusWidth
|
||||
continue
|
||||
}
|
||||
col.SetX(x)
|
||||
col.SetWidth(autoWidth)
|
||||
x += autoWidth
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CompactHeader) SetY(y int) {
|
||||
for _, p := range c.pars {
|
||||
p.SetY(y)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CompactHeader) Buffer() ui.Buffer {
|
||||
buf := ui.NewBuffer()
|
||||
for _, p := range c.pars {
|
||||
@ -130,7 +164,6 @@ func (w *Compact) SetWidth(width int) {
|
||||
x := 1
|
||||
statusWidth := 3
|
||||
autoWidth := (width - statusWidth) / 5
|
||||
log.Infof("autowidth: %d", autoWidth)
|
||||
for n, col := range w.all() {
|
||||
if n == 0 {
|
||||
col.SetX(x)
|
||||
|
Loading…
Reference in New Issue
Block a user