use crate::ui::{Aim, Fill, Model};
pub fn goal(workspace: &str, plan: bool) -> String {
let tail = if plan {
"begun as a plan"
} else {
"Enter begins it"
};
format!("what this conversation on {workspace} is for — {tail}")
}
pub const DOORS: [&str; 2] = ["/login or /config", "pick another on the status bar"];
pub const START_HELP: &str =
"the first message of a new conversation on this workspace; Enter begins it";
pub const SEND_HELP: &str =
"begins a conversation on this workspace with what the box holds, as Enter does";
const OPS: &[&str] = &[crate::verbs::PREPARE, crate::verbs::PROMPT];
pub fn missing(model: &Model) -> Option<String> {
let (Some(worker), Some(_)) = (model.worker(), &model.providers) else {
return None;
};
let lack = match model.worker_row() {
Some(row) if row.bare() => "holds no credential",
Some(_) => return None,
None => "is on no row of this workspace",
};
Some(format!("{} {lack}", worker.provider))
}
fn said(ui: &mut egui::Ui, model: &mut Model, line: &str) {
ui.label(line);
let rows = crate::ui::status::diagnostics::named(model, line);
if rows.is_empty() {
return;
}
let mut fired = None;
ui.horizontal(|ui| {
for row in rows {
let word = format!("{}{}", crate::ui::slash::LEAD, row.word);
let seat =
crate::ui::theme::paint::link(ui, &word, crate::ui::theme::BRAND, row.summary);
crate::ui::act::tag(&seat, row.ops);
if seat.clicked() {
fired = Some(row.word);
}
}
});
if let Some(word) = fired {
crate::ui::slash::fire(model, word, "");
}
}
pub fn render(ui: &mut egui::Ui, model: &mut Model, aim: &Aim) {
let wanted = model.filling() == Some(Fill::Goal);
if let Some(held) = model.start.clone() {
said(ui, model, &held.line());
if held.outstanding() {
return;
}
}
let slashed = crate::ui::slash::parsed(&model.draft).is_some();
let send = super::pills::Send {
live: !model.draft.trim().is_empty(),
help: SEND_HELP,
ops: OPS,
};
let trail = super::pills::Trail::new(ui, model, true, (!slashed).then_some(send));
let reserve = trail.width(ui);
let said = match missing(model) {
Some(lack) => super::hint(ui, &lack, &DOORS, reserve),
None => super::hint(
ui,
&goal(&aim.address, model.plan),
&crate::ui::chat::panel::WAYS,
reserve,
),
};
let mut clicks = super::pills::Clicks::default();
let entry = crate::ui::theme::paint::prompt(
ui,
egui::Id::new(crate::ui::keys::BOX_ID),
&mut model.draft,
&said,
None,
START_HELP,
(reserve, |ui: &mut egui::Ui| trail.paint(ui, &mut clicks)),
);
let pressed = super::pills::spend(ui, model, clicks);
crate::ui::act::tag(&entry, OPS);
if wanted {
entry.request_focus();
}
if slashed {
return;
}
if super::entered(ui, &entry) || pressed {
model.stage(&aim.address);
}
}
#[cfg(test)]
mod tests;