feat: add sorting by cmd
This commit is contained in:
parent
b08c67b752
commit
6d3595f7f7
|
@ -353,7 +353,7 @@ func eventLoop(c gotop.Config, grid *layout.MyGrid) {
|
|||
grid.Proc.ToggleShowingGroupedProcs()
|
||||
ui.Render(grid.Proc)
|
||||
}
|
||||
case "m", "c", "p":
|
||||
case "m", "c", "n", "p":
|
||||
if grid.Proc != nil {
|
||||
grid.Proc.ChangeProcSortMethod(w.ProcSortMethod(e.ID))
|
||||
ui.Render(grid.Proc)
|
||||
|
|
|
@ -25,6 +25,7 @@ const (
|
|||
ProcSortCPU ProcSortMethod = "c"
|
||||
ProcSortMem = "m"
|
||||
ProcSortPid = "p"
|
||||
ProcSortCmd = "n"
|
||||
)
|
||||
|
||||
type Proc struct {
|
||||
|
@ -188,6 +189,9 @@ func (proc *ProcWidget) sortProcs() {
|
|||
case ProcSortMem:
|
||||
sort.Sort(sort.Reverse(SortProcsByMem(*procs)))
|
||||
proc.Header[3] += _downArrow
|
||||
case ProcSortCmd:
|
||||
sort.Sort(sort.Reverse(SortProcsByCmd(*procs)))
|
||||
proc.Header[1] += _downArrow
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -336,3 +340,20 @@ func (procs SortProcsByMem) Swap(i, j int) {
|
|||
func (procs SortProcsByMem) Less(i, j int) bool {
|
||||
return procs[i].Mem < procs[j].Mem
|
||||
}
|
||||
|
||||
type SortProcsByCmd []Proc
|
||||
|
||||
// Len implements Sort interface
|
||||
func (procs SortProcsByCmd) Len() int {
|
||||
return len(procs)
|
||||
}
|
||||
|
||||
// Swap implements Sort interface
|
||||
func (procs SortProcsByCmd) Swap(i, j int) {
|
||||
procs[i], procs[j] = procs[j], procs[i]
|
||||
}
|
||||
|
||||
// Less implements Sort interface
|
||||
func (procs SortProcsByCmd) Less(i, j int) bool {
|
||||
return strings.ToLower(procs[j].CommandName) < strings.ToLower(procs[i].CommandName)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user