Add status column to context tree with tab-stop alignment

SectionView gains a status field for extra info displayed after the
token count column. Memory nodes section shows "N scored, M unscored"
in the status column instead of burying it in the title.

Renderer uses fixed-width columns (40 name, 16 tokens, status) for
consistent alignment across sections.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-07 22:13:27 -04:00
parent 07b400c95c
commit c7c69a8f06
3 changed files with 15 additions and 2 deletions

View file

@ -53,16 +53,18 @@ impl ConsciousScreen {
tokens: ce.tokens, tokens: ce.tokens,
content: ce.entry.message().content_text().to_string(), content: ce.entry.message().content_text().to_string(),
children: Vec::new(), children: Vec::new(),
status: String::new(),
}); });
} }
} }
if !mem_children.is_empty() { if !mem_children.is_empty() {
let mem_tokens: usize = mem_children.iter().map(|c| c.tokens).sum(); let mem_tokens: usize = mem_children.iter().map(|c| c.tokens).sum();
views.push(SectionView { views.push(SectionView {
name: format!("Memory nodes ({} scored, {} unscored)", scored, unscored), name: format!("Memory nodes ({})", mem_children.len()),
tokens: mem_tokens, tokens: mem_tokens,
content: String::new(), content: String::new(),
children: mem_children, children: mem_children,
status: format!("{} scored, {} unscored", scored, unscored),
}); });
} }

View file

@ -139,6 +139,7 @@ impl SubconsciousScreen {
tokens: 0, tokens: 0,
content: val.clone(), content: val.clone(),
children: Vec::new(), children: Vec::new(),
status: String::new(),
} }
}).collect() }).collect()
} }

View file

@ -18,6 +18,8 @@ pub struct SectionView {
pub tokens: usize, pub tokens: usize,
pub content: String, pub content: String,
pub children: Vec<SectionView>, pub children: Vec<SectionView>,
/// Extra status text shown after the token count.
pub status: String,
} }
/// Build a SectionView tree from a ContextSection. /// Build a SectionView tree from a ContextSection.
@ -34,6 +36,7 @@ pub fn section_to_view(section: &ContextSection) -> SectionView {
tokens: ce.tokens, tokens: ce.tokens,
content, content,
children: Vec::new(), children: Vec::new(),
status: String::new(),
} }
}).collect(); }).collect();
SectionView { SectionView {
@ -41,6 +44,7 @@ pub fn section_to_view(section: &ContextSection) -> SectionView {
tokens: section.tokens(), tokens: section.tokens(),
content: String::new(), content: String::new(),
children, children,
status: String::new(),
} }
} }
@ -244,7 +248,13 @@ impl SectionTree {
let indent = " ".repeat(depth + 1); let indent = " ".repeat(depth + 1);
let marker = if !expandable { " " } else if expanded { "" } else { "" }; let marker = if !expandable { " " } else if expanded { "" } else { "" };
let label = format!("{}{} {:30} {:>6} tokens", indent, marker, section.name, section.tokens); let name_col = format!("{}{} {}", indent, marker, section.name);
let tokens_col = format!("{:>6} tokens", section.tokens);
let label = if section.status.is_empty() {
format!("{:40} {}", name_col, tokens_col)
} else {
format!("{:40} {:16} {}", name_col, tokens_col, section.status)
};
let style = if selected { let style = if selected {
Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD) Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD)
} else { } else {