use crate::error::{ErrorContext, KopiError};
use colored::Colorize;
pub fn format_error_chain(error: &KopiError) -> String {
let context = ErrorContext::new(error);
context.to_string()
}
pub fn format_error_with_color(error: &KopiError, use_color: bool) -> String {
colored::control::set_override(use_color);
let context = ErrorContext::new(error);
let mut output = String::new();
output.push_str(&format!("{} {error}\n", "Error:".red().bold()));
if let Some(details) = &context.details {
output.push_str(&format!("\n{details}\n"));
}
if let Some(suggestion) = &context.suggestion {
output.push_str(&format!("\n{}\n", "Suggestions:".yellow().bold()));
for line in suggestion.lines() {
if !line.trim().is_empty() {
output.push_str(&format!("{} {line}\n", "•".cyan()));
}
}
}
output
}