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