mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add redraw handler to reorder rows
This commit is contained in:
parent
995285ebb9
commit
72b643d5d2
22
grid.go
22
grid.go
@ -41,11 +41,18 @@ func (g *Grid) Cursor() {
|
|||||||
ui.Render(ui.Body)
|
ui.Render(ui.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Grid) Rows() (rows []*ui.Row) {
|
func (g *Grid) Redraw() {
|
||||||
|
// reinit body rows
|
||||||
|
ui.Body.Rows = []*ui.Row{}
|
||||||
|
// build layout
|
||||||
|
ui.Body.AddRows(header())
|
||||||
|
|
||||||
for _, c := range g.containers.Sorted() {
|
for _, c := range g.containers.Sorted() {
|
||||||
rows = append(rows, c.widgets.MakeRow())
|
ui.Body.AddRows(c.widgets.MakeRow())
|
||||||
}
|
}
|
||||||
return rows
|
|
||||||
|
ui.Body.Align()
|
||||||
|
ui.Render(ui.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func header() *ui.Row {
|
func header() *ui.Row {
|
||||||
@ -73,13 +80,6 @@ func Display(g *Grid) {
|
|||||||
}
|
}
|
||||||
defer ui.Close()
|
defer ui.Close()
|
||||||
|
|
||||||
// build layout
|
|
||||||
ui.Body.AddRows(header())
|
|
||||||
|
|
||||||
for _, row := range g.Rows() {
|
|
||||||
ui.Body.AddRows(row)
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate layout
|
// calculate layout
|
||||||
ui.Body.Align()
|
ui.Body.Align()
|
||||||
g.Cursor()
|
g.Cursor()
|
||||||
@ -101,7 +101,7 @@ func Display(g *Grid) {
|
|||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
ui.Handle("/timer/1s", func(e ui.Event) {
|
ui.Handle("/timer/1s", func(e ui.Event) {
|
||||||
ui.Render(ui.Body)
|
g.Redraw()
|
||||||
})
|
})
|
||||||
|
|
||||||
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
|
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
|
||||||
|
6
sort.go
6
sort.go
@ -10,7 +10,7 @@ import (
|
|||||||
func NewContainerMap() *ContainerMap {
|
func NewContainerMap() *ContainerMap {
|
||||||
return &ContainerMap{
|
return &ContainerMap{
|
||||||
containers: make(map[string]*Container),
|
containers: make(map[string]*Container),
|
||||||
sortField: "id",
|
sortField: "cpu",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,9 +54,9 @@ func (cm *ContainerMap) Sorted() []*Container {
|
|||||||
case "name":
|
case "name":
|
||||||
sort.Sort(ByName(containers))
|
sort.Sort(ByName(containers))
|
||||||
case "cpu":
|
case "cpu":
|
||||||
sort.Sort(ByCPU(containers))
|
sort.Sort(sort.Reverse(ByCPU(containers)))
|
||||||
case "mem":
|
case "mem":
|
||||||
sort.Sort(ByMem(containers))
|
sort.Sort(sort.Reverse(ByMem(containers)))
|
||||||
default:
|
default:
|
||||||
sort.Sort(ByID(containers))
|
sort.Sort(ByID(containers))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user