fluent-ansi 0.1.0

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

use crate::{Format, ToFormat};

/// A type that represents the reset of all formatting.
///
/// When formatted, it produces the ANSI escape sequence to reset all formatting.
///
/// It is equal to a [`Format::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, "{}", Format::new())
    }
}

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

impl ToFormat for Reset {
    fn to_format(self) -> Format {
        self.into()
    }
}

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

    use super::*;

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

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

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