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)
|
||||
}
|
||||
|
||||
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() {
|
||||
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 {
|
||||
@ -73,13 +80,6 @@ func Display(g *Grid) {
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
// build layout
|
||||
ui.Body.AddRows(header())
|
||||
|
||||
for _, row := range g.Rows() {
|
||||
ui.Body.AddRows(row)
|
||||
}
|
||||
|
||||
// calculate layout
|
||||
ui.Body.Align()
|
||||
g.Cursor()
|
||||
@ -101,7 +101,7 @@ func Display(g *Grid) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
ui.Handle("/timer/1s", func(e ui.Event) {
|
||||
ui.Render(ui.Body)
|
||||
g.Redraw()
|
||||
})
|
||||
|
||||
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
|
||||
|
6
sort.go
6
sort.go
@ -10,7 +10,7 @@ import (
|
||||
func NewContainerMap() *ContainerMap {
|
||||
return &ContainerMap{
|
||||
containers: make(map[string]*Container),
|
||||
sortField: "id",
|
||||
sortField: "cpu",
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,9 +54,9 @@ func (cm *ContainerMap) Sorted() []*Container {
|
||||
case "name":
|
||||
sort.Sort(ByName(containers))
|
||||
case "cpu":
|
||||
sort.Sort(ByCPU(containers))
|
||||
sort.Sort(sort.Reverse(ByCPU(containers)))
|
||||
case "mem":
|
||||
sort.Sort(ByMem(containers))
|
||||
sort.Sort(sort.Reverse(ByMem(containers)))
|
||||
default:
|
||||
sort.Sort(ByID(containers))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user