use crate::ui::keys::{self, Act};
use crate::ui::{Model, slash, theme};
pub const FILTER: &str = "filter";
pub const FILTER_HELP: &str = "narrows this bar's conversations by their words, here on this seat — /find searches the servers";
pub const NEW: &str = "new";
pub const PAGE_MARK: &str = "/";
pub(super) fn new(ui: &mut egui::Ui, model: &mut Model, open: bool) {
let Some(aim) = model.aim.clone() else {
return;
};
if model.covered() && !model.switching {
return;
}
let help = keys::cited(super::NEW_HELP, &[Act::New]);
let (word, chord) = if open {
(NEW, Some((keys::chord_for(Act::New), None)))
} else {
("", None)
};
let seat = ui
.push_id(NEW, |ui| row(ui, super::PLUS, word, chord, help))
.inner;
crate::ui::act::tag(&seat, &[crate::verbs::PREPARE, crate::verbs::PROMPT]);
if seat.clicked() {
model.begin_at(&aim);
model.chose();
}
}
fn row(
ui: &mut egui::Ui,
mark: &str,
word: &str,
aside: Option<(String, Option<theme::State>)>,
help: String,
) -> egui::Response {
theme::paint::Row {
mark: (mark.to_owned(), theme::INK_WEAK),
words: word.to_owned(),
ink: theme::INK,
state: None,
chosen: false,
indent: 0.0,
aside,
beneath: Vec::new(),
tail: None,
door: None,
help,
}
.paint(ui)
}
pub(super) fn render(ui: &mut egui::Ui, model: &mut Model) {
let asking = crate::ui::status::waiting::waiting(model);
let mut fired = None;
for page in slash::rows(model).into_iter().filter(|page| page.page) {
let count = (page.word == crate::ui::queue::WORD && asking > 0)
.then(|| (asking.to_string(), Some(theme::State::Attention)));
let help = keys::cited_word(page.summary, page.word);
let seat = row(ui, PAGE_MARK, page.word, count, help);
crate::ui::act::tag(&seat, page.ops);
if seat.clicked() {
fired = Some(page.word);
}
}
if let Some(word) = fired {
slash::fire(model, word, "");
}
ui.add_space(theme::space::XS);
let id = egui::Id::new(keys::FILTER_ID);
let field = theme::paint::field(ui, id, &mut model.bar.sift, FILTER, None, FILTER_HELP);
if (field.has_focus() || field.lost_focus()) && ui.input(|i| i.key_pressed(egui::Key::Escape)) {
model.bar.sift.clear();
}
ui.add_space(theme::space::XS);
}
pub fn sifted(row: &crate::reply::convs::ConvRow, sift: &str) -> bool {
sift.trim().is_empty()
|| [
Some(row.display.as_str()),
row.name.as_deref(),
Some(row.preview.as_str()),
]
.into_iter()
.flatten()
.any(|words| slash::narrows(words, sift))
}