use crate::reply::diff::{Churn, Diff};
use crate::reply::science::Attempt;
use crate::ui::model::Armed;
pub fn receipt(said: &Armed) -> String {
format!(
"{}: {}",
said.op,
if said.armed {
"it is standing"
} else {
"it is not standing"
}
)
}
pub fn attempt(row: &Attempt) -> Vec<String> {
let mut said = vec![format!(
"{} {} [{}]",
row.diff.ball_id,
row.diff.project,
ending(row)
)];
if let Some(goal) = &row.goal {
said.push(goal.clone());
}
said.push(format!(
"{} steps {}s {} in {} out {} cache-read {} cache-write",
row.steps,
row.wall_secs,
row.usage.input,
row.usage.output,
row.usage.cache_read,
row.usage.cache_write
));
for (what, held) in [
("in", &row.conversation),
("from", &row.base),
("governed by", &row.governing),
("said", &row.response),
] {
if let Some(value) = held {
said.push(format!("{what} {value}"));
}
}
if !row.pins.is_empty() {
said.push(format!("pinned {}", row.pins.join(" ")));
}
for verdict in &row.verdicts {
said.push(format!("{} — {}", verdict.sender, verdict.body));
}
if let Some(n) = row.compacted {
said.push(format!("{n} entries compacted out from under it"));
}
said.push(changed(&row.diff));
said
}
pub fn ending(row: &Attempt) -> String {
let mut said = vec![row.outcome.state.clone()];
for (what, held) in [("at", &row.outcome.commit), ("by", &row.outcome.by)] {
if let Some(value) = held {
said.push(format!("{what} {value}"));
}
}
said.join(" ")
}
pub fn changed(row: &Diff) -> String {
let mut said = vec![format!("{} [{}]", row.ball_id, row.state)];
if let (Some(source), Some(target)) = (&row.source, &row.target) {
said.push(format!("{source} → {target}"));
}
if let Some(handle) = &row.handle {
said.push(format!("candidate {handle}"));
}
if let Some(delivered) = &row.delivered {
said.push(format!("delivered {delivered}"));
}
if !row.missing.is_empty() {
said.push(format!("no such ref: {}", row.missing.join(" ")));
}
if row.truncated == Some(true) {
said.push("(the listing was cut)".to_owned());
}
said.join(" ")
}
pub fn churn(file: &Churn) -> String {
match (file.added, file.removed) {
(Some(added), Some(removed)) => format!("{} +{added} −{removed}", file.path),
_ => format!("{} binary", file.path),
}
}
#[cfg(test)]
mod tests;