use colored::Colorize;
use console::Emoji;
use sara_core::config::OutputConfig;
pub static EMOJI_SUCCESS: Emoji<'_, '_> = Emoji("✅", "[OK]");
pub static EMOJI_ERROR: Emoji<'_, '_> = Emoji("❌", "[ERR]");
pub static EMOJI_WARNING: Emoji<'_, '_> = Emoji("⚠️ ", "[WARN]");
pub static EMOJI_STATS: Emoji<'_, '_> = Emoji("📊", "[STATS]");
pub static EMOJI_ITEM: Emoji<'_, '_> = Emoji("📋", "[ITEM]");
pub fn get_emoji<'a>(config: &OutputConfig, emoji: &Emoji<'a, 'a>) -> &'a str {
if config.emojis { emoji.0 } else { emoji.1 }
}
#[derive(Debug, Clone, Copy, Default)]
pub enum Color {
#[default]
None,
Red,
Green,
Yellow,
Cyan,
}
#[derive(Debug, Clone, Copy, Default)]
pub enum Style {
#[default]
None,
Bold,
Dimmed,
}
pub fn colorize(config: &OutputConfig, text: &str, color: Color, style: Style) -> String {
if !config.colors {
return text.to_string();
}
let colored_text = match color {
Color::Red => text.red(),
Color::Green => text.green(),
Color::Yellow => text.yellow(),
Color::Cyan => text.cyan(),
Color::None => text.normal(),
};
match style {
Style::Bold => colored_text.bold().to_string(),
Style::Dimmed => colored_text.dimmed().to_string(),
Style::None => colored_text.to_string(),
}
}
fn format_message(config: &OutputConfig, emoji: &Emoji, color: Color, message: &str) -> String {
let prefix = get_emoji(config, emoji);
let colored_prefix = if config.emojis {
prefix.to_string()
} else {
colorize(config, prefix, color, Style::None)
};
format!("{} {}", colored_prefix, message)
}
pub fn format_success(config: &OutputConfig, message: &str) -> String {
let msg = colorize(config, message, Color::Green, Style::None);
format_message(config, &EMOJI_SUCCESS, Color::Green, &msg)
}
pub fn print_success(config: &OutputConfig, message: &str) {
println!("{}", format_success(config, message));
}
pub fn format_error(config: &OutputConfig, message: &str) -> String {
let msg = colorize(config, message, Color::Red, Style::None);
format_message(config, &EMOJI_ERROR, Color::Red, &msg)
}
pub fn print_error(config: &OutputConfig, message: &str) {
println!("{}", format_error(config, message));
}
pub fn format_warning(config: &OutputConfig, message: &str) -> String {
let msg = colorize(config, message, Color::Yellow, Style::None);
format_message(config, &EMOJI_WARNING, Color::Yellow, &msg)
}
pub fn print_warning(config: &OutputConfig, message: &str) {
println!("{}", format_warning(config, message));
}
pub fn print_header(config: &OutputConfig, message: &str) {
println!("{}", colorize(config, message, Color::None, Style::Bold));
}
pub fn format_tree_branch(is_last: bool) -> &'static str {
if is_last { "└─" } else { "├─" }
}