1
0
mirror of https://github.com/danog/ytop.git synced 2024-11-27 04:24:45 +01:00

Refactor process sorting

This commit is contained in:
Caleb Bassi 2020-01-20 08:43:01 -08:00
parent 06234a9eb9
commit c60bdc1c24

View File

@ -262,12 +262,12 @@ impl Widget for ProcWidget<'_> {
} else {
self.procs.clone()
};
procs.sort_by(|a, b| match &self.sort_method {
SortMethod::Cpu => a.cpu.partial_cmp(&b.cpu).unwrap(),
SortMethod::Mem => a.mem.partial_cmp(&b.mem).unwrap(),
SortMethod::Num => a.num.cmp(&b.num),
SortMethod::Command => a.commandline.cmp(&b.commandline),
});
match self.sort_method {
SortMethod::Cpu => procs.sort_by(|a, b| a.cpu.partial_cmp(&b.cpu).unwrap()),
SortMethod::Mem => procs.sort_by(|a, b| a.mem.partial_cmp(&b.mem).unwrap()),
SortMethod::Num => procs.sort_by(|a, b| a.num.cmp(&b.num)),
SortMethod::Command => procs.sort_by(|a, b| a.commandline.cmp(&b.commandline)),
}
if self.sort_direction == SortDirection::Down {
procs.reverse();
}