add redraw handler to reorder rows

This commit is contained in:
Bradley Cicenas 2016-12-30 22:10:49 +00:00
parent 995285ebb9
commit 72b643d5d2
2 changed files with 14 additions and 14 deletions

22
grid.go
View File

@ -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) {

View File

@ -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))
}