2022-12-23 20:44:23 -05:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! __ansi_esc {
|
|
|
|
() => {
|
|
|
|
"\x1B"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
pub use __ansi_esc as esc;
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! __ansi_csi {
|
|
|
|
() => {
|
|
|
|
::std::concat!($crate::esc!(), "[")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
pub use __ansi_csi as csi;
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! __ansi_style_code {
|
|
|
|
($code:literal) => {
|
|
|
|
::std::concat!($code)
|
|
|
|
};
|
|
|
|
($code:literal, $($codes:tt)+) => {
|
|
|
|
::std::concat!($code, ";", $crate::style_code!($( $codes )+))
|
|
|
|
};
|
|
|
|
($code:ident, $($codes:tt)+) => {
|
|
|
|
::std::concat!($crate::style_code!($code), ";", $crate::style_code!($( $codes )+))
|
|
|
|
};
|
|
|
|
|
|
|
|
(reset) => {
|
|
|
|
$crate::style_code!(0)
|
|
|
|
};
|
|
|
|
|
|
|
|
(bold) => {
|
|
|
|
$crate::style_code!(1)
|
|
|
|
};
|
|
|
|
(faint) => {
|
|
|
|
$crate::style_code!(2)
|
|
|
|
};
|
|
|
|
(italic) => {
|
|
|
|
$crate::style_code!(3)
|
|
|
|
};
|
|
|
|
(underline) => {
|
|
|
|
$crate::style_code!(4)
|
|
|
|
};
|
|
|
|
(blink) => {
|
|
|
|
$crate::style_code!(5)
|
|
|
|
};
|
|
|
|
(negative) => {
|
|
|
|
$crate::style_code!(7)
|
|
|
|
};
|
2024-04-30 17:26:45 -04:00
|
|
|
(invisible) => {
|
|
|
|
$crate::style_code!(8)
|
|
|
|
};
|
2022-12-23 20:44:23 -05:00
|
|
|
(crossed) => {
|
|
|
|
$crate::style_code!(9)
|
|
|
|
};
|
|
|
|
|
2024-04-30 17:26:45 -04:00
|
|
|
(reset_bold) => {
|
|
|
|
$crate::style_code!(22)
|
|
|
|
};
|
|
|
|
(reset_faint) => {
|
|
|
|
$crate::style_code!(22)
|
|
|
|
};
|
|
|
|
(reset_italic) => {
|
|
|
|
$crate::style_code!(23)
|
|
|
|
};
|
|
|
|
(reset_underline) => {
|
|
|
|
$crate::style_code!(24)
|
|
|
|
};
|
|
|
|
(reset_blink) => {
|
|
|
|
$crate::style_code!(25)
|
|
|
|
};
|
|
|
|
(reset_negative) => {
|
|
|
|
$crate::style_code!(27)
|
|
|
|
};
|
|
|
|
(reset_invisible) => {
|
|
|
|
$crate::style_code!(28)
|
|
|
|
};
|
|
|
|
(reset_crossed) => {
|
|
|
|
$crate::style_code!(29)
|
|
|
|
};
|
|
|
|
|
2022-12-23 20:44:23 -05:00
|
|
|
(black) => {
|
|
|
|
// BACKGROUND COLOR
|
|
|
|
$crate::style_code!(30)
|
|
|
|
};
|
|
|
|
(red) => {
|
|
|
|
$crate::style_code!(31)
|
|
|
|
};
|
|
|
|
(green) => {
|
|
|
|
$crate::style_code!(32)
|
|
|
|
};
|
|
|
|
(yellow) => {
|
|
|
|
$crate::style_code!(33)
|
|
|
|
};
|
|
|
|
(blue) => {
|
|
|
|
$crate::style_code!(34)
|
|
|
|
};
|
|
|
|
(purple) => {
|
|
|
|
$crate::style_code!(35)
|
|
|
|
};
|
|
|
|
(cyan) => {
|
|
|
|
$crate::style_code!(36)
|
|
|
|
};
|
|
|
|
(white) => {
|
|
|
|
$crate::style_code!(37)
|
|
|
|
};
|
2024-04-30 17:26:45 -04:00
|
|
|
(reset_color) => {
|
|
|
|
$crate::style_code!(39)
|
|
|
|
};
|
2022-12-23 20:44:23 -05:00
|
|
|
}
|
|
|
|
pub use __ansi_style_code as style_code;
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! __ansi_style {
|
|
|
|
($( $tt:tt )+) => {
|
|
|
|
::std::concat!($crate::csi!(), $crate::style_code!($( $tt )+), "m")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
pub use __ansi_style as style;
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! __ansi_styled {
|
|
|
|
( [$( $style:tt )+], $fmt:literal ) => {
|
|
|
|
::std::concat!($crate::style!($( $style )+), $fmt, $crate::style!(reset))
|
|
|
|
};
|
|
|
|
( [$( $style:tt )+], $fmt:literal, $( $args:tt )+ ) => {
|
|
|
|
::std::format!($crate::styled!([$( $style )+], $fmt), $( $args )+)
|
|
|
|
};
|
|
|
|
|
|
|
|
( $( $style:ident, )+ $fmt:literal ) => {
|
|
|
|
$crate::styled!([$( $style ),+], $fmt)
|
|
|
|
};
|
|
|
|
( $( $style:ident, )+ $fmt:literal, $( $args:tt )+ ) => {
|
|
|
|
$crate::styled!([$( $style ),+], $fmt, $( $args )+)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
pub use __ansi_styled as styled;
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! __ansi_define {
|
|
|
|
( $name:ident = $( $style:tt )+ ) => {
|
|
|
|
$crate::define!(@ $name = [ $( $style )+ ], $);
|
|
|
|
};
|
|
|
|
(@ $name:ident = [ $( $style:tt )+ ], $dol:tt) => {
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! $name {
|
|
|
|
($dol( $tokens:tt )+) => {
|
|
|
|
$crate::styled!([$( $style )+], $dol( $tokens )+)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
pub use __ansi_define as define;
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn styled_literal() {
|
|
|
|
assert_eq!(
|
|
|
|
styled!(bold, green, "Hello, World!"),
|
|
|
|
"\x1B[1;32mHello, World!\x1B[0m"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|