stylic 0.3.1

A simple, fast library for styling text with ANSI escape codes
Documentation
macro_rules! impl_attribute_methods {
    ($($(#[$meta:meta])* $set:ident $variant:ident)*) => {
        $(
            $(#[$meta])*
            #[inline]
            pub const fn $set(self) -> Self {
                self.attributes(Attributes::$variant)
            }
        )*
    };
}
pub(crate) use impl_attribute_methods;

macro_rules! impl_color_methods {
    (
        colors($($variant:ident)*)
        fg($($(#[$fg_meta:meta])* $set_fg:ident)*)
        bg($($(#[$bg_meta:meta])* $set_bg:ident)*)
        underline($($(#[$underline_meta:meta])* $set_underline:ident)*)
    ) => {
        $(
            $(#[$fg_meta])*
            #[inline]
            pub const fn $set_fg(self) -> Self {
                self.fg(Color::Basic(BasicColor::$variant))
            }

            $(#[$bg_meta])*
            #[inline]
            pub const fn $set_bg(self) -> Self {
                self.bg(Color::Basic(BasicColor::$variant))
            }

            $(#[$underline_meta])*
            #[inline]
            pub const fn $set_underline(self) -> Self {
                self.underline_colored(Color::Basic(BasicColor::$variant))
            }
        )*
    };
}
pub(crate) use impl_color_methods;

macro_rules! builder_methods {
    ($s:ident => $style:expr) => {
        /// Set the foreground color.
        #[inline]
        pub const fn fg(self, color: Color) -> Self {
            let mut $s = self;
            $style.fg = color;
            $s
        }

        /// Set the background color.
        #[inline]
        pub const fn bg(self, color: Color) -> Self {
            let mut $s = self;
            $style.bg = color;
            $s
        }

        /// Set the underline attribute and color.
        #[inline]
        pub const fn underline_colored(self, color: Color) -> Self {
            let mut $s = self;
            let style = &mut $style;
            style.underline = color;
            style.attributes = style.attributes.or(Attributes::UNDERLINED);
            $s
        }

        /// Set the attributes.
        ///
        /// This will not unset any existing attributes.
        #[inline]
        pub const fn attributes(self, attrs: Attributes) -> Self {
            let mut $s = self;
            let style = &mut $style;
            style.attributes = style.attributes.or(attrs);
            $s
        }

        $crate::builder::impl_attribute_methods!(
            /// Set the bold attribute.
            bold BOLD
            /// Set the dim attribute.
            dim DIM
            /// Set the italic attribute.
            italic ITALIC
            /// Set the underline attribute.
            underlined UNDERLINED
            /// Set the blink attribute.
            blink BLINK
            /// Set the inverted attribute.
            inverted INVERTED
            /// Set the hidden attribute.
            hidden HIDDEN
            /// Set the strikethrough attribute.
            strikethrough STRIKETHROUGH
        );

        $crate::builder::impl_color_methods!(
            colors(
                Black
                Red
                Green
                Yellow
                Blue
                Magenta
                Cyan
                White

                BrightBlack
                BrightRed
                BrightGreen
                BrightYellow
                BrightBlue
                BrightMagenta
                BrightCyan
                BrightWhite
            )

            fg(
                /// Set the foreground color to black.
                black
                /// Set the foreground color to red.
                red
                /// Set the foreground color to green.
                green
                /// Set the foreground color to yellow.
                yellow
                /// Set the foreground color to blue.
                blue
                /// Set the foreground color to magenta.
                magenta
                /// Set the foreground color to cyan.
                cyan
                /// Set the foreground color to white.
                white

                /// Set the foreground color to bright black.
                bright_black
                /// Set the foreground color to bright red.
                bright_red
                /// Set the foreground color to bright green.
                bright_green
                /// Set the foreground color to bright yellow.
                bright_yellow
                /// Set the foreground color to bright blue.
                bright_blue
                /// Set the foreground color to bright magenta.
                bright_magenta
                /// Set the foreground color to bright cyan.
                bright_cyan
                /// Set the foreground color to bright white.
                bright_white
            )

            bg(
                /// Set the background color to black.
                on_black
                /// Set the background color to red.
                on_red
                /// Set the background color to green.
                on_green
                /// Set the background color to yellow.
                on_yellow
                /// Set the background color to blue.
                on_blue
                /// Set the background color to magenta.
                on_magenta
                /// Set the background color to cyan.
                on_cyan
                /// Set the background color to white.
                on_white

                /// Set the background color to bright black.
                on_bright_black
                /// Set the background color to bright red.
                on_bright_red
                /// Set the background color to bright green.
                on_bright_green
                /// Set the background color to bright yellow.
                on_bright_yellow
                /// Set the background color to bright blue.
                on_bright_blue
                /// Set the background color to bright magenta.
                on_bright_magenta
                /// Set the background color to bright cyan.
                on_bright_cyan
                /// Set the background color to bright white.
                on_bright_white
            )

            underline(
                /// Set the underline attribute, and set the underline color to black.
                underline_black
                /// Set the underline attribute, and set the underline color to red.
                underline_red
                /// Set the underline attribute, and set the underline color to green.
                underline_green
                /// Set the underline attribute, and set the underline color to yellow.
                underline_yellow
                /// Set the underline attribute, and set the underline color to blue.
                underline_blue
                /// Set the underline attribute, and set the underline color to magenta.
                underline_magenta
                /// Set the underline attribute, and set the underline color to cyan.
                underline_cyan
                /// Set the underline attribute, and set the underline color to white.
                underline_white

                /// Set the underline attribute, and set the underline color to bright black.
                underline_bright_black
                /// Set the underline attribute, and set the underline color to bright red.
                underline_bright_red
                /// Set the underline attribute, and set the underline color to bright green.
                underline_bright_green
                /// Set the underline attribute, and set the underline color to bright yellow.
                underline_bright_yellow
                /// Set the underline attribute, and set the underline color to bright blue.
                underline_bright_blue
                /// Set the underline attribute, and set the underline color to bright magenta.
                underline_bright_magenta
                /// Set the underline attribute, and set the underline color to bright cyan.
                underline_bright_cyan
                /// Set the underline attribute, and set the underline color to bright white.
                underline_bright_white
            )
        );
    };
}

pub(crate) use builder_methods;