Lines
95.24 %
Functions
50 %
Branches
100 %
//! The filter builder overlay: its rows and the cursor.
use ratatui::text::{Line, Text};
use tvui::{Role, Theme};
use crate::modal::FilterBuilder;
/// The body and the line the cursor is on.
pub(super) fn content(builder: &FilterBuilder, theme: &Theme) -> (Text<'static>, usize) {
let view = builder.view();
let mut lines = vec![Line::from(view.heading)];
if let Some(notice) = view.notice {
lines.extend(notice.lines().map(|line| Line::from(line.to_string())));
}
if let Some(error) = &builder.error {
lines.push(Line::from(format!("! {error}")));
lines.push(Line::from(""));
let first = lines.len();
if view.rows.is_empty() {
lines.push(Line::from(" (no rows)"));
lines.extend(view.rows.iter().enumerate().map(|(index, row)| {
if index == view.selected {
Line::styled(format!("> {row}"), theme.style(Role::DialogFocus))
} else {
Line::from(format!(" {row}"))
}));
(Text::from(lines), first + view.selected)