use super::{Kind, Row};
use crate::ui::theme::glyph;
const HEAD: usize = 60;
pub(super) fn met(rows: Vec<Row>) -> Vec<Row> {
let mut out: Vec<Row> = Vec::with_capacity(rows.len());
for row in rows {
let asked = (row.kind == Kind::Result)
.then(|| {
out.iter_mut()
.rev()
.find(|call| call.kind == Kind::Call && call.call == row.call)
})
.flatten();
match asked {
Some(call) => {
call.kind = Kind::Answered;
call.said = row.said;
call.fold = row.fold;
call.failed = row.failed;
}
None => out.push(row),
}
}
out
}
pub(super) fn head(name: &str, input: &str) -> String {
if input.is_empty() {
return name.to_owned();
}
let argument = match serde_json::from_str::<serde_json::Value>(input) {
Ok(serde_json::Value::Object(map)) => map
.values()
.next()
.map_or_else(String::new, ToString::to_string),
Ok(value) => value.to_string(),
Err(_) => input.to_owned(),
};
let line = argument.lines().next().unwrap_or_default();
let mut said: String = line.chars().take(HEAD).collect();
if said.len() < argument.len() {
said.push_str(glyph::ELIDED);
}
format!("{name}({said})")
}
#[cfg(test)]
mod tests;