Add expand/collapse all, per-pane key legends
SectionTree: - 'e': expand all nodes - 'c': collapse all nodes - Home/End already wired from previous commit Key legend shown at bottom border of each focused pane: - Tree panes: nav, expand/collapse, expand/collapse all, paging - Agent list: select, tab - History: scroll, paging Legend only appears on the focused pane to avoid clutter. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
19bb6d02e3
commit
578be807e7
3 changed files with 54 additions and 14 deletions
|
|
@ -48,6 +48,14 @@ pub fn format_ts_age(ts: i64) -> String {
|
|||
format_age((now - ts).max(0) as f64)
|
||||
}
|
||||
|
||||
/// Key legend for SectionTree panes.
|
||||
pub fn tree_legend() -> Line<'static> {
|
||||
Line::styled(
|
||||
" ↑↓:nav →/Enter:expand ←:collapse e:expand all c:collapse all PgUp/Dn Home/End ",
|
||||
Style::default().fg(Color::DarkGray),
|
||||
)
|
||||
}
|
||||
|
||||
/// Render a paragraph with a vertical scrollbar.
|
||||
pub fn render_scrollable(
|
||||
frame: &mut Frame,
|
||||
|
|
@ -90,6 +98,14 @@ impl SectionTree {
|
|||
Self { selected: None, expanded: std::collections::HashSet::new(), scroll: 0 }
|
||||
}
|
||||
|
||||
/// Total nodes in the tree (regardless of expand state).
|
||||
fn total_nodes(&self, sections: &[ContextSection]) -> usize {
|
||||
fn count_all(section: &ContextSection) -> usize {
|
||||
1 + section.children.iter().map(|c| count_all(c)).sum::<usize>()
|
||||
}
|
||||
sections.iter().map(|s| count_all(s)).sum()
|
||||
}
|
||||
|
||||
pub fn item_count(&self, sections: &[ContextSection]) -> usize {
|
||||
fn count(section: &ContextSection, expanded: &std::collections::HashSet<usize>, idx: &mut usize) -> usize {
|
||||
let my_idx = *idx;
|
||||
|
|
@ -146,6 +162,17 @@ impl SectionTree {
|
|||
self.expanded.remove(&sel);
|
||||
}
|
||||
}
|
||||
KeyCode::Char('e') => {
|
||||
// Expand all
|
||||
let total = self.total_nodes(sections);
|
||||
for i in 0..total {
|
||||
self.expanded.insert(i);
|
||||
}
|
||||
}
|
||||
KeyCode::Char('c') => {
|
||||
// Collapse all
|
||||
self.expanded.clear();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.scroll_to_selected(height);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue