feat(maestro): add the ctrl-k command bar to the TUI

Opens from Normal and Insert mode as an ordinary keymap entry, so it is
rebindable and the help overlay picks it up from the live keymap. An
empty query lists sessions most recently focused first, matching the web
bar's `orderSessionsForBar`; typing ranks through `matcher.rs` with the
matched ranges highlighted, grouped under kind headers.

Enter attaches through the same path the sidebar's attach uses, Escape
closes and leaves focus and mode where they were.
This commit is contained in:
Miguel Palhas
2026-09-03 16:42:21 +01:00
parent 83741d7203
commit dc783778c8
9 changed files with 1204 additions and 2 deletions
+758
View File
@@ -0,0 +1,758 @@
//! The `ctrl-k` command bar (`docs/COMMAND-BAR.md`): a query line over a
//! result list, opened from Normal or Insert mode, closed with Escape.
//!
//! Sessions are the only kind here (#153); the sigils (#154), the session
//! action page (#155) and the leader's literal Ctrl-K (#156) land later. The
//! grouping below is already kind-generic so those slot in without a rewrite.
//!
//! Ranking is [`crate::matcher`]'s job and nothing here reorders it — the
//! groups are a rendering of the ranked list, in the order their best-scoring
//! member appears. The web bar (`web/src/commandBar.ts`) implements the same
//! contract; the two must agree.
use maestro_protocol::display::{abbreviate_dir, command_tool, session_tree_path};
use maestro_protocol::{Session, SessionStatus};
use ratatui::layout::Rect;
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
use ratatui::Frame;
use uuid::Uuid;
use crate::input::InputKey;
use crate::matcher::{
match_and_rank, CandidateKind, MatchCandidate, MatchFieldName, MatchRange, SessionCandidate,
};
use crate::overlays::centered;
use crate::palette;
use crate::text_input::TextInput;
/// What Enter on a row does. Only sessions exist today; `>` commands and `~`
/// directories (#154) become further variants.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BarTarget {
Session(Uuid),
}
/// One row of the result list, already resolved to what it renders and what it
/// opens. Headers are labels, not rows, so they are never in this list.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BarRow {
pub kind: CandidateKind,
pub target: BarTarget,
/// Primary text — the name as the sidebar shows it.
pub name: String,
/// Secondary text: the field the match was found in when that was not the
/// name, so a session found through its directory says so.
pub meta: Option<String>,
/// The field that won, and the ranges inside it. `None` for an empty
/// query, which matches everything and highlights nothing.
pub field: Option<MatchFieldName>,
pub ranges: Vec<MatchRange>,
pub dead: bool,
}
impl BarRow {
/// Whether the highlight belongs on [`Self::meta`] rather than the name.
fn meta_is_matched(&self) -> bool {
!matches!(self.field, None | Some(MatchFieldName::Name))
}
}
/// One kind's slice of the ranked list, as a header plus the rows under it.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BarGroup {
pub kind: CandidateKind,
pub title: &'static str,
/// Index of this group's first row in [`CommandBar::rows`].
pub start: usize,
pub len: usize,
}
fn kind_title(kind: CandidateKind) -> &'static str {
match kind {
CandidateKind::Session => "Sessions",
CandidateKind::Command => "Commands",
CandidateKind::Directory => "Directories",
}
}
/// What a keystroke asked the bar to do.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BarOutcome {
/// The bar stays up.
Stay,
/// Escape: close and give the keyboard back.
Close,
/// Enter on a row: close and open what it points at.
Open(BarTarget),
}
/// The empty-query order (`docs/COMMAND-BAR.md`, "Empty query"): most recently
/// focused first; a session that has never been focused sorts after every
/// session that has, most recently created first among those; and a dead
/// session sorts after every live one regardless of recency, because a session
/// you cannot attach to is not where you just were.
///
/// This is also the input order for a non-empty query, which is what the
/// matcher's last tie-break preserves. Mirrors the web's
/// `orderSessionsForBar`.
pub fn order_sessions_for_bar(sessions: &[Session]) -> Vec<&Session> {
let mut ordered: Vec<&Session> = sessions.iter().collect();
ordered.sort_by(|a, b| {
let dead = |s: &Session| u8::from(s.status == SessionStatus::Dead);
dead(a)
.cmp(&dead(b))
.then_with(|| {
a.last_focused_at
.is_none()
.cmp(&b.last_focused_at.is_none())
})
.then_with(|| match (a.last_focused_at, b.last_focused_at) {
(Some(x), Some(y)) => y.cmp(&x),
_ => std::cmp::Ordering::Equal,
})
.then_with(|| b.created_at.cmp(&a.created_at))
});
ordered
}
/// One session's candidate: the fields `docs/COMMAND-BAR.md`'s candidate table
/// names, with the directory abbreviated the way the sidebar shows it.
pub fn session_candidate(session: &Session, home_dir: &str) -> SessionCandidate {
SessionCandidate {
name: crate::sidebar::name_for(session),
directory: session_tree_path(session).map(|path| abbreviate_dir(&path, home_dir)),
command: (!session.command.is_empty()).then(|| session.command.clone()),
tool: command_tool(&session.command).map(str::to_string),
}
}
/// The bar's state while it is up: the query buffer, the candidates it was
/// opened over, the rows the current query produces, and the highlight.
#[derive(Debug)]
pub struct CommandBar {
input: TextInput,
/// Matcher input, in the empty-query order. Never reordered — the matcher's
/// last tie-break is what keeps that order meaningful.
candidates: Vec<MatchCandidate>,
/// What each candidate opens, parallel to `candidates`.
targets: Vec<BarTarget>,
/// Whether each candidate's session is dead, parallel to `candidates`.
dead: Vec<bool>,
rows: Vec<BarRow>,
highlight: usize,
}
impl CommandBar {
/// Open the bar over the sessions the catalog has right now.
pub fn new(sessions: &[Session], home_dir: &str) -> Self {
let ordered = order_sessions_for_bar(sessions);
let candidates = ordered
.iter()
.map(|s| MatchCandidate::Session(session_candidate(s, home_dir)))
.collect();
let targets = ordered.iter().map(|s| BarTarget::Session(s.id)).collect();
let dead = ordered
.iter()
.map(|s| s.status == SessionStatus::Dead)
.collect();
let mut bar = Self {
input: TextInput::default(),
candidates,
targets,
dead,
rows: Vec::new(),
highlight: 0,
};
bar.recompute();
bar
}
pub fn query(&self) -> &str {
self.input.value()
}
pub fn rows(&self) -> &[BarRow] {
&self.rows
}
pub fn highlight(&self) -> usize {
self.highlight
}
/// The row Enter would open.
pub fn selected(&self) -> Option<&BarRow> {
self.rows.get(self.highlight)
}
/// Group the ranked rows by kind for rendering. Grouping never reorders:
/// a group holds its matches in rank order, and groups appear in the order
/// their best-scoring member does — so the first row under the first
/// header is the globally best result.
pub fn groups(&self) -> Vec<BarGroup> {
let mut groups: Vec<BarGroup> = Vec::new();
for (index, row) in self.rows.iter().enumerate() {
match groups.iter_mut().find(|g| g.kind == row.kind) {
Some(group) => group.len += 1,
None => groups.push(BarGroup {
kind: row.kind,
title: kind_title(row.kind),
start: index,
len: 1,
}),
}
}
groups
}
/// Move the highlight. It does not wrap: it stops at the first and last
/// row.
pub fn move_highlight(&mut self, delta: isize) {
if self.rows.is_empty() {
self.highlight = 0;
return;
}
let last = self.rows.len() as isize - 1;
let next = (self.highlight as isize + delta).clamp(0, last);
self.highlight = next as usize;
}
/// Feed the bar a key. Everything the key table (`docs/COMMAND-BAR.md`,
/// "Keys") does not claim is ordinary editing.
pub fn handle_key(&mut self, key: &InputKey) -> BarOutcome {
match key {
InputKey::Esc => BarOutcome::Close,
InputKey::Enter => match self.selected() {
Some(row) => BarOutcome::Open(row.target),
// Nothing to open: the bar stays up rather than closing on a
// key that did nothing.
None => BarOutcome::Stay,
},
InputKey::Up
| InputKey::Char {
c: 'p', ctrl: true, ..
} => {
self.move_highlight(-1);
BarOutcome::Stay
}
InputKey::Down
| InputKey::Char {
c: 'n', ctrl: true, ..
} => {
self.move_highlight(1);
BarOutcome::Stay
}
// Tab drills into the highlighted session's action page (#155).
// Until then it is inert rather than a literal tab in the query.
InputKey::Tab | InputKey::BackTab => BarOutcome::Stay,
other => {
let before = self.input.value().to_string();
self.input.handle_key(other);
if self.input.value() != before {
self.recompute();
}
BarOutcome::Stay
}
}
}
/// Re-rank for the current query. The highlight starts on the globally
/// best row every time the list changes: an old index would point at a
/// different result.
fn recompute(&mut self) {
let rows: Vec<BarRow> = {
let results = match_and_rank(self.input.value(), &self.candidates);
results
.iter()
.map(|result| {
let index = self
.candidates
.iter()
.position(|c| std::ptr::eq(c, result.candidate))
.expect("every result borrows one of this bar's candidates");
let MatchCandidate::Session(session) = result.candidate else {
unreachable!("sessions are the only kind the bar builds (#153)")
};
BarRow {
kind: CandidateKind::Session,
target: self.targets[index],
name: session.name.clone(),
meta: meta_text(session, result.field),
field: result.field,
ranges: result.ranges.clone(),
dead: self.dead[index],
}
})
.collect()
};
self.rows = rows;
self.highlight = 0;
}
/// Draw the bar and return where the terminal cursor belongs.
pub fn render(&self, f: &mut Frame, parent: Rect) -> Option<(u16, u16)> {
let pal = palette::active();
let height = parent.height.saturating_sub(4).clamp(5, 20);
let area = centered(parent, 72, height);
f.render_widget(Clear, area);
let block = Block::default()
.title(" go to ")
.borders(Borders::ALL)
.style(pal.card.base())
.border_style(pal.border_style(true));
let inner = block.inner(area);
f.render_widget(block, area);
if inner.height < 3 || inner.width == 0 {
return None;
}
let row = |offset: u16| Rect {
x: inner.x,
y: inner.y + offset,
width: inner.width,
height: 1,
};
// Query line, then the results, then the key hint on the last row.
let query = row(0);
let col = self
.input
.render(query, f.buffer_mut(), pal.card.text_style());
f.render_widget(
Paragraph::new(Line::from(Span::styled(
"[enter] open [esc] close",
pal.card.dim_style(),
))),
row(inner.height - 1),
);
let list_height = inner.height.saturating_sub(2) as usize;
if list_height > 0 {
for (offset, line) in self.visible_lines(list_height).into_iter().enumerate() {
f.render_widget(Paragraph::new(line), row(1 + offset as u16));
}
}
Some((col, query.y))
}
/// The result lines that fit in `height`, scrolled so the highlighted row
/// is on screen.
fn visible_lines(&self, height: usize) -> Vec<Line<'static>> {
let pal = palette::active();
if self.rows.is_empty() {
return vec![Line::from(Span::styled(
"No matches",
pal.card.muted_style(),
))];
}
// Headers and rows, in one list, remembering which line the highlight
// sits on so the scroll can keep it visible.
let mut lines: Vec<Line<'static>> = Vec::new();
let mut highlight_line = 0usize;
for group in self.groups() {
lines.push(Line::from(Span::styled(
group.title.to_string(),
pal.group_row_style(),
)));
for index in group.start..group.start + group.len {
if index == self.highlight {
highlight_line = lines.len();
}
lines.push(self.row_line(index));
}
}
let scroll = highlight_line.saturating_sub(height.saturating_sub(1));
lines.into_iter().skip(scroll).take(height).collect()
}
fn row_line(&self, index: usize) -> Line<'static> {
let pal = palette::active();
let row = &self.rows[index];
let selected = index == self.highlight;
let surface = pal.surface(selected);
let base = if row.dead {
surface.dim_style()
} else {
surface.text_style()
};
let hit = base.add_modifier(Modifier::BOLD | Modifier::UNDERLINED);
let mut spans = vec![Span::styled(if selected { "› " } else { " " }, base)];
let name_ranges: &[MatchRange] = if row.meta_is_matched() {
&[]
} else {
&row.ranges
};
spans.extend(highlighted_spans(&row.name, name_ranges, base, hit));
if let Some(meta) = &row.meta {
let meta_style = surface.muted_style();
let meta_hit = meta_style.add_modifier(Modifier::BOLD | Modifier::UNDERLINED);
spans.push(Span::styled(" ", base));
let meta_ranges: &[MatchRange] = if row.meta_is_matched() {
&row.ranges
} else {
&[]
};
spans.extend(highlighted_spans(meta, meta_ranges, meta_style, meta_hit));
}
Line::from(spans)
}
}
/// The secondary line under a row's name: the field the match was found in
/// when that was not the name, so a session found through its directory says
/// so. Mirrors the web's `metaText`.
fn meta_text(session: &SessionCandidate, field: Option<MatchFieldName>) -> Option<String> {
match field {
Some(MatchFieldName::Directory) => session.directory.clone(),
Some(MatchFieldName::Command) => session.command.clone(),
Some(MatchFieldName::Tool) => session.tool.clone(),
_ => session.directory.clone(),
}
}
/// Split `text` into styled spans, with the matcher's `[start, end)` character
/// ranges carrying `hit` and everything else `base`.
fn highlighted_spans(
text: &str,
ranges: &[MatchRange],
base: Style,
hit: Style,
) -> Vec<Span<'static>> {
let chars: Vec<char> = text.chars().collect();
let slice = |from: usize, to: usize| -> String {
chars[from.min(chars.len())..to.min(chars.len())]
.iter()
.collect()
};
let mut spans = Vec::new();
let mut cursor = 0usize;
for &(start, end) in ranges {
if start > cursor {
spans.push(Span::styled(slice(cursor, start), base));
}
spans.push(Span::styled(slice(start, end), hit));
cursor = end;
}
if cursor < chars.len() {
spans.push(Span::styled(slice(cursor, chars.len()), base));
}
spans
}
#[cfg(test)]
mod tests {
use super::*;
use chrono::{DateTime, TimeZone, Utc};
use ratatui::backend::TestBackend;
use ratatui::Terminal;
use std::collections::HashMap;
use std::path::PathBuf;
fn at(secs: i64) -> DateTime<Utc> {
Utc.timestamp_opt(1_700_000_000 + secs, 0).unwrap()
}
fn session(n: u128, command: &str) -> Session {
Session {
id: Uuid::from_u128(n),
cwd: PathBuf::from("/home/me/dev/api"),
command: command.to_string(),
env: HashMap::new(),
metadata: HashMap::new(),
worktree: None,
status: SessionStatus::Running,
created_at: at(0),
foreground: None,
activity: Default::default(),
activity_detail: None,
last_activity_at: at(0),
activity_since: at(0),
current_cwd: None,
blocked_work: None,
last_focused_at: None,
}
}
fn named(n: u128, name: &str) -> Session {
let mut s = session(n, "bash");
s.metadata
.insert("name".into(), serde_json::Value::String(name.to_string()));
s
}
fn ids(rows: &[BarRow]) -> Vec<Uuid> {
rows.iter()
.map(|r| match r.target {
BarTarget::Session(id) => id,
})
.collect()
}
fn typed(bar: &mut CommandBar, text: &str) {
for c in text.chars() {
bar.handle_key(&InputKey::Char {
c,
ctrl: false,
alt: false,
shift: false,
});
}
}
#[test]
fn empty_query_lists_sessions_most_recently_focused_first() {
let mut a = named(1, "alpha");
a.last_focused_at = Some(at(10));
let mut b = named(2, "bravo");
b.last_focused_at = Some(at(30));
let mut c = named(3, "charlie");
c.last_focused_at = Some(at(20));
let bar = CommandBar::new(&[a, b, c], "/home/me");
assert_eq!(
ids(bar.rows()),
vec![Uuid::from_u128(2), Uuid::from_u128(3), Uuid::from_u128(1)]
);
// Every row matches with no ranges, so nothing is highlighted inside.
assert!(bar.rows().iter().all(|r| r.ranges.is_empty()));
}
#[test]
fn never_focused_sessions_sort_after_focused_ones_newest_first() {
let mut focused = named(1, "focused");
focused.last_focused_at = Some(at(5));
let mut older = named(2, "older");
older.created_at = at(10);
let mut newer = named(3, "newer");
newer.created_at = at(20);
let bar = CommandBar::new(&[older, newer, focused], "/home/me");
assert_eq!(
ids(bar.rows()),
vec![Uuid::from_u128(1), Uuid::from_u128(3), Uuid::from_u128(2)]
);
}
/// A session you cannot attach to is not where you just were.
#[test]
fn dead_sessions_sort_after_live_ones_however_recent() {
let mut dead = named(1, "dead");
dead.status = SessionStatus::Dead;
dead.last_focused_at = Some(at(99));
let live = named(2, "live");
let bar = CommandBar::new(&[dead, live], "/home/me");
assert_eq!(
ids(bar.rows()),
vec![Uuid::from_u128(2), Uuid::from_u128(1)]
);
assert!(bar.rows()[1].dead);
}
#[test]
fn typing_ranks_through_the_matcher_and_returns_ranges() {
let mut bar = CommandBar::new(&[named(1, "web-search"), named(2, "websearch")], "/home/me");
typed(&mut bar, "ws");
// F9: the `s` after `-` earns the boundary bonus.
assert_eq!(
ids(bar.rows()),
vec![Uuid::from_u128(1), Uuid::from_u128(2)]
);
assert_eq!(bar.rows()[0].ranges, vec![(0, 1), (4, 5)]);
assert_eq!(bar.rows()[0].field, Some(MatchFieldName::Name));
}
#[test]
fn a_query_matching_nothing_leaves_no_rows() {
let mut bar = CommandBar::new(&[named(1, "alpha")], "/home/me");
typed(&mut bar, "zzz");
assert!(bar.rows().is_empty());
assert!(bar.selected().is_none());
}
/// A session found through its directory highlights inside the directory,
/// which is also what the row's meta text shows.
#[test]
fn a_directory_match_highlights_in_the_meta_text() {
let mut worker = named(1, "worker");
worker.cwd = PathBuf::from("/home/me/dev/api");
let mut bar = CommandBar::new(&[worker], "/home/me");
typed(&mut bar, "api");
assert_eq!(bar.rows()[0].field, Some(MatchFieldName::Directory));
assert_eq!(bar.rows()[0].meta.as_deref(), Some("~/dev/api"));
assert_eq!(bar.rows()[0].ranges, vec![(6, 9)]);
}
/// The candidate's `tool` is the mark the card's icon stands for, so
/// `claude` reaches a session whose name says nothing about it.
#[test]
fn the_tool_field_is_a_candidate_field() {
let mut nameless = named(1, "nameless");
nameless.command = "claude --resume".into();
let mut bar = CommandBar::new(&[nameless, named(2, "clay")], "/home/me");
typed(&mut bar, "claude");
assert_eq!(ids(bar.rows()), vec![Uuid::from_u128(1)]);
assert_eq!(bar.rows()[0].field, Some(MatchFieldName::Tool));
}
#[test]
fn results_group_under_kind_headers_with_the_best_row_first() {
let bar = CommandBar::new(&[named(1, "alpha"), named(2, "bravo")], "/home/me");
let groups = bar.groups();
assert_eq!(groups.len(), 1);
assert_eq!(groups[0].title, "Sessions");
assert_eq!(groups[0].kind, CandidateKind::Session);
assert_eq!((groups[0].start, groups[0].len), (0, 2));
// The highlight starts on the globally best row.
assert_eq!(bar.highlight(), 0);
}
#[test]
fn arrows_and_ctrl_pn_move_the_highlight_without_wrapping() {
let mut bar = CommandBar::new(
&[named(1, "alpha"), named(2, "bravo"), named(3, "charlie")],
"/home/me",
);
assert_eq!(bar.handle_key(&InputKey::Down), BarOutcome::Stay);
assert_eq!(bar.highlight(), 1);
bar.handle_key(&InputKey::Char {
c: 'n',
ctrl: true,
alt: false,
shift: false,
});
assert_eq!(bar.highlight(), 2);
// Stops at the last row rather than wrapping to the first.
bar.handle_key(&InputKey::Down);
assert_eq!(bar.highlight(), 2);
bar.handle_key(&InputKey::Char {
c: 'p',
ctrl: true,
alt: false,
shift: false,
});
assert_eq!(bar.highlight(), 1);
bar.handle_key(&InputKey::Up);
bar.handle_key(&InputKey::Up);
assert_eq!(bar.highlight(), 0);
}
#[test]
fn enter_opens_the_highlighted_session_and_escape_closes() {
let mut bar = CommandBar::new(&[named(1, "alpha"), named(2, "bravo")], "/home/me");
bar.handle_key(&InputKey::Down);
assert_eq!(
bar.handle_key(&InputKey::Enter),
BarOutcome::Open(BarTarget::Session(Uuid::from_u128(2)))
);
assert_eq!(bar.handle_key(&InputKey::Esc), BarOutcome::Close);
}
#[test]
fn enter_with_no_results_leaves_the_bar_up() {
let mut bar = CommandBar::new(&[named(1, "alpha")], "/home/me");
typed(&mut bar, "zzz");
assert_eq!(bar.handle_key(&InputKey::Enter), BarOutcome::Stay);
}
#[test]
fn editing_the_query_re_ranks_and_resets_the_highlight() {
let mut bar = CommandBar::new(&[named(1, "alpha"), named(2, "alpine")], "/home/me");
bar.handle_key(&InputKey::Down);
assert_eq!(bar.highlight(), 1);
typed(&mut bar, "alp");
assert_eq!(bar.query(), "alp");
assert_eq!(bar.highlight(), 0);
bar.handle_key(&InputKey::Backspace);
assert_eq!(bar.query(), "al");
assert_eq!(bar.rows().len(), 2);
}
/// Backspacing back to an empty query is not a special key: the list
/// becomes the recency order again.
#[test]
fn backspacing_to_an_empty_query_restores_the_recency_order() {
let mut recent = named(1, "alpha");
recent.last_focused_at = Some(at(50));
let older = named(2, "alpine");
let mut bar = CommandBar::new(&[older, recent], "/home/me");
typed(&mut bar, "alpi");
assert_eq!(ids(bar.rows()), vec![Uuid::from_u128(2)]);
for _ in 0..4 {
bar.handle_key(&InputKey::Backspace);
}
assert_eq!(bar.query(), "");
assert_eq!(
ids(bar.rows()),
vec![Uuid::from_u128(1), Uuid::from_u128(2)]
);
}
fn render_to_string(bar: &CommandBar, w: u16, h: u16) -> String {
let backend = TestBackend::new(w, h);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| {
bar.render(f, f.area());
})
.unwrap();
let buf = terminal.backend().buffer().clone();
let mut out = String::new();
for y in 0..buf.area.height {
for x in 0..buf.area.width {
out.push_str(buf[(x, y)].symbol());
}
out.push('\n');
}
out
}
#[test]
fn renders_the_query_the_headers_and_the_rows() {
let mut bar = CommandBar::new(&[named(1, "alpha"), named(2, "alpine")], "/home/me");
typed(&mut bar, "alp");
let rendered = render_to_string(&bar, 90, 20);
assert!(rendered.contains("go to"), "{rendered}");
assert!(rendered.contains("alp"), "{rendered}");
assert!(rendered.contains("Sessions"), "{rendered}");
assert!(rendered.contains("alpha"), "{rendered}");
assert!(rendered.contains("alpine"), "{rendered}");
assert!(rendered.contains("[esc] close"), "{rendered}");
}
#[test]
fn renders_a_no_results_state() {
let mut bar = CommandBar::new(&[named(1, "alpha")], "/home/me");
typed(&mut bar, "zzz");
let rendered = render_to_string(&bar, 90, 20);
assert!(rendered.contains("No matches"), "{rendered}");
}
/// The matched characters are drawn bold, so the row shows why it matched.
#[test]
fn matched_ranges_are_styled_apart_from_the_rest_of_the_row() {
let mut bar = CommandBar::new(&[named(1, "web-search")], "/home/me");
typed(&mut bar, "ws");
let backend = TestBackend::new(90, 20);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| {
bar.render(f, f.area());
})
.unwrap();
let buf = terminal.backend().buffer().clone();
let mut bold: Vec<String> = Vec::new();
for y in 0..buf.area.height {
for x in 0..buf.area.width {
let cell = &buf[(x, y)];
if cell.style().add_modifier.contains(Modifier::BOLD)
&& cell.style().add_modifier.contains(Modifier::UNDERLINED)
{
bold.push(cell.symbol().to_string());
}
}
}
assert_eq!(bold, vec!["w", "s"], "bold cells: {bold:?}");
}
}