use console::measure_text_width;
use textwrap;
use textwrap::wrap;
pub fn pad_str(s: &str, width: usize) -> String {
let actual_width = measure_text_width(s);
if actual_width >= width {
s.chars().take(width).collect()
} else {
let mut result = String::from(s);
result.push_str(&" ".repeat(width - actual_width));
result
}
}
pub fn wrap_text(text: &str, width: usize) -> Vec<String> {
if text.is_empty() {
return vec![" ".repeat(width)];
}
let wrapped: Vec<String> = textwrap::wrap(text, width)
.into_iter()
.map(|cow| cow.into_owned())
.collect();
if wrapped.is_empty() {
return vec![" ".repeat(width)];
}
wrapped.into_iter().map(|line| pad_str(&line, width)).collect()
}