pub const COL_WIDTH: usize = 80;
pub fn word_wrap(text: &str, first_indent: &str, cont_indent: &str, col: usize) -> Vec<String> {
let mut lines: Vec<String> = Vec::new();
let mut current = first_indent.to_string();
for word in text.split_whitespace() {
let at_indent = current == first_indent || current == cont_indent;
let needed = if at_indent {
current.len() + word.len()
} else {
current.len() + 1 + word.len()
};
if needed > col && !at_indent {
lines.push(current);
current = format!("{}{}", cont_indent, word);
} else if at_indent {
current.push_str(word);
} else {
current.push(' ');
current.push_str(word);
}
}
if !current.trim().is_empty() {
lines.push(current);
}
lines
}
pub fn truncate(s: &str, max: usize) -> String {
let chars: Vec<char> = s.chars().collect();
if chars.len() <= max {
s.to_string()
} else {
let cut: String = chars[..max.saturating_sub(1)].iter().collect();
format!("{}…", cut)
}
}