fluent-ansi 0.3.0

A fluent interface for ANSI terminal colors and styles in Rust.
Documentation
use core::fmt::{Display, Formatter, Result};

use crate::{Style, ToStyle};

/// A type that represents the reset of all styling.
///
/// When rendered, it produces the ANSI escape sequence to reset all styling.
///
/// It is equal to a [`Style::new()`].
///
/// See [The `Reset` singleton](crate#the-reset-singleton).
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct Reset;

impl Display for Reset {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        write!(f, "{}", Style::new())
    }
}

impl PartialEq<Style> for Reset {
    fn eq(&self, other: &Style) -> bool {
        self.to_style() == *other
    }
}

impl ToStyle for Reset {
    fn to_style(self) -> Style {
        self.into()
    }
}

#[cfg(test)]
mod tests {
    use crate::{ToStyleSet as _, assert_display};

    use super::*;

    #[test]
    fn reset() {
        assert_display!(Reset, "\x1b[0m");
    }

    #[test]
    fn eq() {
        assert_eq!(Reset, Reset);
        assert_eq!(Reset, Style::new());
        assert_ne!(Reset, Style::new().bold());
        assert_eq!(Style::new(), Reset);
        assert_ne!(Style::new().bold(), Reset);
    }

    #[test]
    fn to_style() {
        assert_eq!(Reset.to_style(), Style::new());
    }
}