#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Style {
Bold,
Dim,
Italic,
Underline,
Blink,
Reverse,
Hidden,
Strikethrough,
Reset,
}
impl Style {
#[must_use]
pub const fn to_str(&self) -> &'static str {
match self {
Self::Bold => "\x1b[1m",
Self::Dim => "\x1b[2m",
Self::Italic => "\x1b[3m",
Self::Underline => "\x1b[4m",
Self::Blink => "\x1b[5m",
Self::Reverse => "\x1b[7m",
Self::Hidden => "\x1b[8m",
Self::Strikethrough => "\x1b[9m",
Self::Reset => "\x1b[0m",
}
}
}
impl std::fmt::Display for Style {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_str())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_style_codes() {
assert_eq!(Style::Bold.to_str(), "\x1b[1m");
assert_eq!(Style::Reset.to_str(), "\x1b[0m");
assert_eq!(Style::Dim.to_str(), "\x1b[2m");
}
}