use super::theme;
use anstream::println as styled_println;
use anstyle::{Color, Effects, Reset, Style};
pub struct Styles;
impl Styles {
pub fn error() -> Style {
theme::active_styles().error
}
pub fn warning() -> Style {
theme::active_styles().secondary
}
pub fn success() -> Style {
theme::active_styles().primary
}
pub fn info() -> Style {
theme::active_styles().output
}
pub fn debug() -> Style {
theme::active_styles().response
}
pub fn bold() -> Style {
Style::new().effects(Effects::BOLD)
}
pub fn bold_error() -> Style {
theme::active_styles().error.bold()
}
pub fn bold_success() -> Style {
theme::active_styles().primary.bold()
}
pub fn bold_warning() -> Style {
theme::active_styles().secondary.bold()
}
pub fn header() -> Style {
let accent = theme::banner_color();
Style::new()
.fg_color(Some(Color::Rgb(accent)))
.effects(Effects::BOLD)
}
pub fn code() -> Style {
theme::active_styles().secondary
}
pub fn render(style: &Style) -> String {
format!("{}", style)
}
pub fn render_reset() -> String {
format!("{}", Reset)
}
}
pub fn error(message: &str) {
styled_println!(
"{}{}{}",
Styles::render(&Styles::error()),
message,
Styles::render_reset()
);
}
pub fn warning(message: &str) {
styled_println!(
"{}{}{}",
Styles::render(&Styles::warning()),
message,
Styles::render_reset()
);
}
pub fn success(message: &str) {
styled_println!(
"{}{}{}",
Styles::render(&Styles::success()),
message,
Styles::render_reset()
);
}
pub fn info(message: &str) {
styled_println!(
"{}{}{}",
Styles::render(&Styles::info()),
message,
Styles::render_reset()
);
}
pub fn debug(message: &str) {
styled_println!(
"{}{}{}",
Styles::render(&Styles::debug()),
message,
Styles::render_reset()
);
}
pub fn bold(message: &str) {
styled_println!(
"{}{}{}",
Styles::render(&Styles::bold()),
message,
Styles::render_reset()
);
}
pub fn styled(style: &Style, message: &str) {
styled_println!(
"{}{}{}",
Styles::render(style),
message,
Styles::render_reset()
);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_styles() {
error("Test error");
warning("Test warning");
success("Test success");
info("Test info");
debug("Test debug");
bold("Test bold");
styled(&Styles::header(), "Test custom");
}
}