use console::{style, StyledObject};
pub fn success(msg: impl std::fmt::Display) -> StyledObject<String> {
style(msg.to_string()).green()
}
pub fn error(msg: impl std::fmt::Display) -> StyledObject<String> {
style(msg.to_string()).red().bold()
}
pub fn warn(msg: impl std::fmt::Display) -> StyledObject<String> {
style(msg.to_string()).yellow()
}
pub fn heading(msg: impl std::fmt::Display) -> StyledObject<String> {
style(msg.to_string()).cyan().bold()
}
pub fn muted(msg: impl std::fmt::Display) -> StyledObject<String> {
style(msg.to_string()).dim()
}
pub fn separator(width: usize) -> StyledObject<String> {
muted("━".repeat(width))
}
const PALETTE: [Palette; 5] = [
Palette::Cyan,
Palette::Magenta,
Palette::Green,
Palette::Yellow,
Palette::Blue,
];
#[derive(Clone, Copy)]
enum Palette {
Cyan,
Magenta,
Green,
Yellow,
Blue,
}
pub fn palette(index: usize, msg: impl std::fmt::Display) -> StyledObject<String> {
let styled = style(msg.to_string());
match PALETTE[index % PALETTE.len()] {
Palette::Cyan => styled.cyan(),
Palette::Magenta => styled.magenta(),
Palette::Green => styled.green(),
Palette::Yellow => styled.yellow(),
Palette::Blue => styled.blue(),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn palette_wraps_around() {
assert_eq!(format!("{}", palette(0, "x")), format!("{}", palette(5, "x")));
}
}