add sorting by container state

This commit is contained in:
Bradley Cicenas 2017-02-22 05:20:37 +00:00
parent 9b483ba2f3
commit a1fdd8fb49
2 changed files with 13 additions and 1 deletions

View File

@ -64,7 +64,7 @@ func (g *Grid) cursorUp() {
func (g *Grid) cursorDown() {
idx := g.cursorIdx()
// increment if possible
if idx > (len(g.containers) - 1) {
if idx >= (len(g.containers) - 1) {
return
}
if idx >= g.maxRows-1 {

12
sort.go
View File

@ -16,6 +16,18 @@ var Sorters = map[string]sortMethod{
"mem": func(c1, c2 *Container) bool { return c1.metrics.MemUsage < c2.metrics.MemUsage },
"mem %": func(c1, c2 *Container) bool { return c1.metrics.MemPercent < c2.metrics.MemPercent },
"net": func(c1, c2 *Container) bool { return sumNet(c1) < sumNet(c2) },
"state": func(c1, c2 *Container) bool {
if c1.state == "running" {
return true
}
if c2.state == "running" {
return false
}
if c2.state == "paused" {
return false
}
return true
},
}
func SortFields() (fields []string) {