use crate::reply::Outcome;
use crate::reply::enrolled::Enrolled;
use crate::reply::login::Signin;
use crate::reply::providers::ProviderRow;
use crate::reply::start::Prepared;
use super::parts::{brief, clause, line, line_over, listing, when};
pub(super) fn outcome(outcome: &Outcome) -> String {
listing(
&line(vec![
Some(if outcome.ok() { "ok" } else { "failed" }.to_owned()),
when(!outcome.ok(), &format!("exit {}", outcome.exit)),
]),
[
when(!outcome.stdout.is_empty(), outcome.stdout.trim_end()),
when(!outcome.stderr.is_empty(), outcome.stderr.trim_end()),
]
.into_iter()
.flatten()
.collect(),
"",
)
}
pub(super) fn prepared(prepared: &Prepared) -> String {
line_over(
&format!("staged in {}", prepared.workspace),
Some(prepared.goal.clone()),
)
}
pub(super) fn fanned(candidates: &[Prepared]) -> String {
listing(
"candidates",
candidates.iter().map(prepared).collect(),
"the spread produced no candidate",
)
}
pub(super) fn enrolled(enrolled: &Enrolled) -> String {
format!(
"enrolled {} at {} ({} grade) — its material is in this frame and is not printed; \
`lernie enroll` shows the symbol that carries it",
enrolled.name, enrolled.address, enrolled.grade
)
}
pub(super) fn login(signin: &Signin) -> String {
listing(
&line(vec![
Some("sign-in".to_owned()),
clause(
"exit",
signin.outcome.map(|code| code.to_string()).as_deref(),
),
clause("fallback:", signin.fallback.as_deref()),
]),
signin.lines.iter().map(|said| said.text.clone()).collect(),
"it said nothing",
)
}
pub(super) fn providers(rows: &[ProviderRow]) -> String {
let painted = rows
.iter()
.map(|row| {
line(vec![
Some(row.name.clone()),
when(row.signable(), "signable"),
clause("blocked:", row.blocked.as_deref().map(brief).as_deref()),
row.takes(),
Some(row.fact.clone()),
])
})
.collect();
listing("providers", painted, "this wall can sign in to nothing")
}
pub(super) fn models(rows: &[String]) -> String {
listing("models", rows.to_vec(), "that provider offers no model")
}
pub(super) fn answered(
tool: &str,
tool_use: &str,
verdict: &str,
scope: &str,
advanced: bool,
) -> String {
line(vec![
Some(format!("{tool} ({tool_use}): {verdict}")),
Some(format!("for this {scope}")),
Some(if advanced { "advanced" } else { "still parked" }.to_owned()),
])
}
pub(super) fn delivered(
base: &str,
target: &str,
source: Option<&str>,
commit: Option<&str>,
) -> String {
line(vec![
Some(format!("delivered onto {target}")),
Some(format!("base {base}")),
clause("from", source),
clause("as", commit),
when(commit.is_none(), "(it landed nothing)"),
])
}
pub(super) fn retired(discarded: bool) -> String {
if discarded {
"retired, and its source ref went with it".to_owned()
} else {
"retired; its source ref is kept".to_owned()
}
}
pub(super) fn floored(standing: bool) -> String {
if standing {
"a floor stands over it".to_owned()
} else {
"no floor stands over it".to_owned()
}
}
pub(super) fn armed(standing: bool) -> String {
if standing {
"it is armed".to_owned()
} else {
"it is not armed".to_owned()
}
}