Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort Procs By Cmd #208

Merged
merged 2 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/gotop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions dicts/de_DE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Process actions:

Prozesssortierung:
- c: CPU
- n: Cmd
- m: Mem
- p: PID

Expand Down
1 change: 1 addition & 0 deletions dicts/en_US.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Process actions:

Process sorting:
- c: CPU
- n: Cmd
- m: Mem
- p: PID

Expand Down
1 change: 1 addition & 0 deletions dicts/eo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Proceza agoj:

Proceza ordigoj:
- c: CPU
- n: Cmd
- m: Memoro
- p: PID

Expand Down
1 change: 1 addition & 0 deletions dicts/es.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Acciones de proceso :

Ordenación de procesos:
- c: CPU
- n: Cmd
- m: Mem
- p: PID

Expand Down
1 change: 1 addition & 0 deletions dicts/fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Action sur les processus:

Tri des processus:
- c: CPU
- n: Cmd
- m: Mem
- p: PID

Expand Down
1 change: 1 addition & 0 deletions dicts/ru_RU.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ help="""
- d9: убить выбранный процесс или группу процессов с помощью SIGKILL (9)
Сортировка процессов:
- c: CPU
- n: Cmd
- m: Память
- p: PID
Фильтр процессов:
Expand Down
1 change: 1 addition & 0 deletions dicts/tt_TT.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ gnipuorg ssecorp elggot :>baT< -

:gnitros ssecorP
UPC :c -
dmC :n -
meM :m -
DIP :p -

Expand Down
1 change: 1 addition & 0 deletions dicts/zh_CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ help="""

进程排序:
- c: CPU
- n: Cmd
- m: 内存
- p: 进程标识

Expand Down
21 changes: 21 additions & 0 deletions widgets/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
ProcSortCPU ProcSortMethod = "c"
ProcSortMem = "m"
ProcSortPid = "p"
ProcSortCmd = "n"
)

type Proc struct {
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)
}