Skip to content

Commit 9ea1571

Browse files
oandrewfacebook-github-bot
authored andcommitted
Add ViewRc::process_view_default_tree to select the default process view style between tree/flat
Summary: Let users configure the default style via `~/.config/below/belowrc`. ``` $ cat ~/.config/below/belowrc [view] # tree view by default process_view_default_tree = true ``` Reviewed By: dschatzberg Differential Revision: D79680432 fbshipit-source-id: 54ade6685f25f182ff9c98e0405d036f2b6bfc1a
1 parent f77e29d commit 9ea1571

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

below/view/src/process_view.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl StateCommon for ProcessState {
8787
_ => self
8888
.sort_tags
8989
.get(tab)
90-
.unwrap_or_else(|| panic!("Fail to find tab: {}", tab))
90+
.unwrap_or_else(|| panic!("Fail to find tab: {tab}"))
9191
.view_items
9292
.get(idx - 2)
9393
.expect("Out of title scope")
@@ -177,6 +177,10 @@ impl ProcessState {
177177
self.fold = !self.fold;
178178
}
179179

180+
pub fn set_tree_view(&mut self, enable: bool) {
181+
self.tree_view = enable;
182+
}
183+
180184
pub fn toggle_tree_view(&mut self) {
181185
self.tree_view = !self.tree_view;
182186
}
@@ -247,12 +251,17 @@ impl ProcessView {
247251
let user_data = c
248252
.user_data::<ViewState>()
249253
.expect("No data stored in Cursive Object!");
254+
255+
let mut process_state = ProcessState::new(user_data.process.clone());
256+
if let Some(process_view_default_tree) = user_data.viewrc.process_view_default_tree {
257+
process_state.set_tree_view(process_view_default_tree);
258+
}
250259
StatsView::new(
251260
"process",
252261
tabs,
253262
tabs_map,
254263
list,
255-
ProcessState::new(user_data.process.clone()),
264+
process_state,
256265
user_data.event_controllers.clone(),
257266
user_data.cmd_controllers.clone(),
258267
)
@@ -365,6 +374,6 @@ impl ViewBridge for ProcessView {
365374
.get(selected_key /* pid */)
366375
.and_then(|spm| spm.query(&tag))
367376
.map_or("?".to_string(), |field| field.to_string());
368-
format!(" {} : {} ", tag, field_str)
377+
format!(" {tag} : {field_str} ")
369378
}
370379
}

below/view/src/viewrc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ pub struct ViewRc {
5353
pub cgroup_name_width: Option<usize>,
5454
// Extra rows to add in the summary view.
5555
pub summary_view_extra_rows: Option<Vec<SummaryViewExtraRow>>,
56+
// Show process view as tree instead of list by default.
57+
// When not set, defaults to true (tree view).
58+
pub process_view_default_tree: Option<bool>,
5659
}
5760

5861
impl ViewRc {
@@ -84,7 +87,7 @@ impl ViewRc {
8487
}
8588
Err(e) => (
8689
Default::default(),
87-
Some(format!("Failed to parse belowrc: {}", e)),
90+
Some(format!("Failed to parse belowrc: {e}")),
8891
),
8992
},
9093
_ => (Default::default(), None),

0 commit comments

Comments
 (0)