diff --git a/grid.go b/grid.go index 8f13ee5..eae3a4f 100644 --- a/grid.go +++ b/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) { diff --git a/sort.go b/sort.go index 653bcd7..d2aaa7a 100644 --- a/sort.go +++ b/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)) }