1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:07:35 +00:00

ps: Sort using input order in case of -q

Now the output of `ps -q <list>` is sorted according to the order the
user specified.
This commit is contained in:
Mahmoud Mandour 2021-08-28 11:13:15 +02:00 committed by Ali Mohammad Pur
parent 259ecb3d11
commit ac7c83689b

View file

@ -110,9 +110,14 @@ int main(int argc, char** argv)
}
processes.remove_all_matching([&](auto& a) { return selected_pids.find(a.pid) == selected_pids.end(); });
}
quick_sort(processes, [](auto& a, auto& b) { return a.pid < b.pid; });
auto processes_sort_predicate = [&selected_pids](auto& a, auto& b) {
return selected_pids.find_first_index(a.pid).value() < selected_pids.find_first_index(b.pid).value();
};
quick_sort(processes, processes_sort_predicate);
} else {
quick_sort(processes, [](auto& a, auto& b) { return a.pid < b.pid; });
}
Vector<Vector<String>> rows;
rows.ensure_capacity(1 + processes.size());