use ratatui::text::Line;
#[derive(Debug, Clone)]
pub struct FormattedOutput<'a> {
pub header: Line<'a>,
pub body: Vec<Line<'a>>,
pub footer: Option<Line<'a>>,
}
pub trait ToolFormatter {
fn format<'a>(&self, tool_name: &str, output: &str) -> FormattedOutput<'a>;
fn handles(&self, tool_name: &str) -> bool;
}
pub fn truncate_lines(text: &str, max_lines: usize) -> String {
let lines: Vec<&str> = text.lines().collect();
if lines.len() <= max_lines {
return text.to_string();
}
let head_count = max_lines * 2 / 3;
let tail_count = max_lines - head_count - 1;
let omitted = lines.len() - head_count - tail_count;
let mut result = lines[..head_count].join("\n");
result.push_str(&format!("\n... ({omitted} lines omitted) ...\n"));
result.push_str(&lines[lines.len() - tail_count..].join("\n"));
result
}
pub fn indent(text: &str, spaces: usize) -> String {
let prefix = " ".repeat(spaces);
text.lines()
.map(|line| {
if line.is_empty() {
String::new()
} else {
format!("{prefix}{line}")
}
})
.collect::<Vec<_>>()
.join("\n")
}
#[cfg(test)]
#[path = "base_tests.rs"]
mod tests;