mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add stateMap for consistent state sorting
This commit is contained in:
18
sort.go
18
sort.go
@@ -9,6 +9,13 @@ import (
|
|||||||
|
|
||||||
type sortMethod func(c1, c2 *Container) bool
|
type sortMethod func(c1, c2 *Container) bool
|
||||||
|
|
||||||
|
var stateMap = map[string]int{
|
||||||
|
"running": 3,
|
||||||
|
"paused": 2,
|
||||||
|
"exited": 1,
|
||||||
|
"created": 0,
|
||||||
|
}
|
||||||
|
|
||||||
var idSorter = func(c1, c2 *Container) bool { return c1.id < c2.id }
|
var idSorter = func(c1, c2 *Container) bool { return c1.id < c2.id }
|
||||||
var nameSorter = func(c1, c2 *Container) bool { return c1.name < c2.name }
|
var nameSorter = func(c1, c2 *Container) bool { return c1.name < c2.name }
|
||||||
|
|
||||||
@@ -50,16 +57,7 @@ var Sorters = map[string]sortMethod{
|
|||||||
if c1.state == c2.state {
|
if c1.state == c2.state {
|
||||||
return nameSorter(c1, c2)
|
return nameSorter(c1, c2)
|
||||||
}
|
}
|
||||||
if c1.state == "running" {
|
return stateMap[c1.state] > stateMap[c2.state]
|
||||||
return true
|
|
||||||
}
|
|
||||||
if c2.state == "running" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if c2.state == "paused" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user