use crate::ui::theme::{ThemeEntry, ThemeStyle};
use owo_colors::OwoColorize;
use std::collections::HashMap;
use std::io::{self, Write};
pub(crate) fn get_styled_text(
text: &str,
entry: ThemeEntry,
theme_map: &HashMap<ThemeEntry, ThemeStyle>,
) -> String {
if let Some(style) = theme_map.get(&entry) {
if let Some(color) = &style.fg {
return text.color(color.to_ansi_color()).to_string();
}
}
text.color(owo_colors::AnsiColors::White).to_string()
}
pub fn print_message<W: Write>(
writer: &mut W,
message: &str,
theme_map: &HashMap<ThemeEntry, ThemeStyle>,
theme_entry: Option<ThemeEntry>,
) -> io::Result<()> { let final_theme_entry = theme_entry.unwrap_or(ThemeEntry::Info); let styled_message = get_styled_text(&format!("{}\n", message), final_theme_entry, theme_map);
write!(writer, "{}", styled_message) }
pub fn print_info_message<W: Write>(
writer: &mut W,
message: &str,
theme_map: &HashMap<ThemeEntry, ThemeStyle>,
) -> io::Result<()> { let styled_message = get_styled_text(&format!("{}\n", message), ThemeEntry::Info, theme_map);
write!(writer, "{}", styled_message) }
pub fn print_error_message<W: Write>(
writer: &mut W,
message: &str,
theme_map: &HashMap<ThemeEntry, ThemeStyle>,
) -> io::Result<()> { let styled_message = get_styled_text(&format!("ERROR: {}\n", message), ThemeEntry::Error, theme_map);
write!(writer, "{}", styled_message) }
pub fn print_warn_message<W: Write>(
writer: &mut W,
message: &str,
theme_map: &HashMap<ThemeEntry, ThemeStyle>,
) -> io::Result<()> { let styled_message = get_styled_text(&format!("WARNING: {}\n", message), ThemeEntry::Warn, theme_map);
write!(writer, "{}", styled_message) }