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

feature: Adds tree view #223

Merged
merged 21 commits into from
Sep 7, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Fix sort being reversed for trees
  • Loading branch information
ClementTsang committed Sep 7, 2020
commit 3aba4b4337700b51ba61421d7b4c73f96ada9102
11 changes: 8 additions & 3 deletions src/data_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ pub fn tree_process_data(
single_process_data: &[ConvertedProcessData], is_using_command: bool,
sort_type: &ProcessSorting, is_sort_descending: bool,
) -> Vec<ConvertedProcessData> {
// TODO: [TREE] Allow for collapsing entries.

// Let's first build up a (really terrible) parent -> child mapping...
// At the same time, let's make a mapping of PID -> process data!
let mut parent_child_mapping: HashMap<Pid, IndexSet<Pid>> = HashMap::default();
Expand Down Expand Up @@ -596,9 +598,11 @@ pub fn tree_process_data(
// Now let's sort the immediate children!
sort_vec(&mut to_sort_vec, sort_type, is_sort_descending);

// Need to reverse what we got, apparently...
if let Some(current_mapping) = parent_child_mapping.get_mut(&current_pid) {
*current_mapping = to_sort_vec
.iter()
.rev()
.map(|(pid, _proc)| *pid)
.collect::<IndexSet<Pid>>();
}
Expand Down Expand Up @@ -657,10 +661,9 @@ pub fn tree_process_data(
)
}),
ProcessSorting::Pid => {
// Note we only sort if is_sort_descending as otherwise it's repeated.
if is_sort_descending {
to_sort_vec.sort_by(|a, b| {
utils::gen_util::get_ordering(a.1.pid, b.1.pid, is_sort_descending)
utils::gen_util::get_ordering(a.0, b.0, is_sort_descending)
});
}
}
Expand Down Expand Up @@ -691,7 +694,9 @@ pub fn tree_process_data(
is_sort_descending,
)
}),
ProcessSorting::Count => {}
ProcessSorting::Count => {
// Should never occur in this case.
}
}
}

Expand Down