#[macro_use]
extern crate lazy_static;
pub mod dot {
#[derive(Copy, Clone)]
pub enum DotColors {
Reset ,
Black = 30 ,
Red ,
Green ,
Yellow ,
Blue ,
Magenta ,
Cyan ,
White ,
Default = 39 ,
LightBlack = 90 ,
LightRed ,
LightGreen ,
LightYellow ,
LightBlue ,
LightMagenta ,
LightCyan ,
LightWhite ,
LightDefault = 99 ,
ForegroundBlack = 40 ,
ForegroundRed ,
ForegroundGreen ,
ForegroundYellow ,
ForegroundBlue ,
ForegroundMagenta ,
ForegroundCyan ,
ForegroundWhite ,
ForegroundDefault = 49 ,
ForegroundLightBlack = 100,
ForegroundLightRed ,
ForegroundLightGreen ,
ForegroundLightYellow ,
ForegroundLightBlue ,
ForegroundLightMagenta ,
ForegroundLightCyan ,
ForegroundLightWhite ,
ForegroundLightDefault=109
}
pub struct DotTrueColor {
pub r: u32,
pub g: u32,
pub b: u32
}
pub enum DotTypes {
Light ,
Bold ,
Dim ,
Underlined,
Blink ,
Reverse ,
Hidden
}
macro_rules! makedot {
($type:expr, $color:expr) => {
format!("\x1b[{};{}m", stringify!($type as u8), stringify!($color as u8))
};
}
pub mod dot_defineds {
lazy_static! {
pub static ref BLACK_COLOR : String = makedot!(DotTypes::Light, DotColors::Black );
pub static ref RED_COLOR : String = makedot!(DotTypes::Light, DotColors::Red );
pub static ref GREEN_COLOR : String = makedot!(DotTypes::Light, DotColors::Green );
pub static ref YELLOW_COLOR : String = makedot!(DotTypes::Light, DotColors::Yellow );
pub static ref BLUE_COLOR : String = makedot!(DotTypes::Light, DotColors::Blue );
pub static ref MAGENTA_COLOR: String = makedot!(DotTypes::Light, DotColors::Magenta);
pub static ref CYAN_COLOR : String = makedot!(DotTypes::Light, DotColors::Cyan );
pub static ref WHITE_COLOR : String = makedot!(DotTypes::Light, DotColors::White );
pub static ref DEFAULT_COLOR: String = makedot!(DotTypes::Light, DotColors::Default);
pub static ref LIGHT_BLACK_COLOR : String = makedot!(DotTypes::Light, DotColors::LightBlack );
pub static ref LIGHT_RED_COLOR : String = makedot!(DotTypes::Light, DotColors::LightRed );
pub static ref LIGHT_GREEN_COLOR : String = makedot!(DotTypes::Light, DotColors::LightGreen );
pub static ref LIGHT_YELLOW_COLOR : String = makedot!(DotTypes::Light, DotColors::LightYellow );
pub static ref LIGHT_BLUE_COLOR : String = makedot!(DotTypes::Light, DotColors::LightBlue );
pub static ref LIGHT_MAGENTA_COLOR: String = makedot!(DotTypes::Light, DotColors::LightMagenta);
pub static ref LIGHT_CYAN_COLOR : String = makedot!(DotTypes::Light, DotColors::LightCyan );
pub static ref LIGHT_WHITE_COLOR : String = makedot!(DotTypes::Light, DotColors::LightWhite );
pub static ref LIGHT_DEFAULT_COLOR: String = makedot!(DotTypes::Light, DotColors::LightDefault);
pub static ref FG_BLACK_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundBlack );
pub static ref FG_RED_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundRed );
pub static ref FG_GREEN_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundGreen );
pub static ref FG_YELLOW_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundYellow );
pub static ref FG_BLUE_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundBlue );
pub static ref FG_MAGENTA_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundMagenta);
pub static ref FG_CYAN_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundCyan );
pub static ref FG_WHITE_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundWhite );
pub static ref FG_DEFAULT_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundDefault);
pub static ref FG_LIGHT_BLACK_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundLightBlack );
pub static ref FG_LIGHT_RED_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundLightRed );
pub static ref FG_LIGHT_GREEN_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundLightGreen );
pub static ref FG_LIGHT_YELLOW_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundLightYellow );
pub static ref FG_LIGHT_BLUE_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundLightBlue );
pub static ref FG_LIGHT_MAGENTA_COLOR: String = makedot!(DotTypes::Light, DotColors::ForegroundLightMagenta);
pub static ref FG_LIGHT_CYAN_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundLightCyan );
pub static ref FG_LIGHT_WHITE_COLOR : String = makedot!(DotTypes::Light, DotColors::ForegroundLightWhite );
pub static ref FG_LIGHT_DEFAULT_COLOR: String = makedot!(DotTypes::Light, DotColors::ForegroundLightDefault);
}
}
macro_rules! printdot {
($type:expr, $color:expr) => {
print!("\x1b[{};{}m", $type as u8, $color as u8);
};
}
pub fn black () { printdot!(DotTypes::Light, DotColors::Black ); }
pub fn red () { printdot!(DotTypes::Light, DotColors::Red ); }
pub fn green () { printdot!(DotTypes::Light, DotColors::Green ); }
pub fn yellow () { printdot!(DotTypes::Light, DotColors::Yellow ); }
pub fn blue () { printdot!(DotTypes::Light, DotColors::Blue ); }
pub fn magenta () { printdot!(DotTypes::Light, DotColors::Magenta ); }
pub fn cyan () { printdot!(DotTypes::Light, DotColors::Cyan ); }
pub fn white () { printdot!(DotTypes::Light, DotColors::White ); }
pub fn default () { printdot!(DotTypes::Light, DotColors::Default ); }
pub fn light_black () { printdot!(DotTypes::Light, DotColors::LightBlack ); }
pub fn light_red () { printdot!(DotTypes::Light, DotColors::LightRed ); }
pub fn light_green () { printdot!(DotTypes::Light, DotColors::LightGreen ); }
pub fn light_yellow () { printdot!(DotTypes::Light, DotColors::LightYellow ); }
pub fn light_blue () { printdot!(DotTypes::Light, DotColors::LightBlue ); }
pub fn light_magenta() { printdot!(DotTypes::Light, DotColors::LightMagenta); }
pub fn light_cyan () { printdot!(DotTypes::Light, DotColors::LightCyan ); }
pub fn light_white () { printdot!(DotTypes::Light, DotColors::LightWhite ); }
pub fn light_default() { printdot!(DotTypes::Light, DotColors::LightDefault); }
pub fn fg_black () { printdot!(DotTypes::Light, DotColors::ForegroundBlack ); }
pub fn fg_red () { printdot!(DotTypes::Light, DotColors::ForegroundRed ); }
pub fn fg_green () { printdot!(DotTypes::Light, DotColors::ForegroundGreen ); }
pub fn fg_yellow () { printdot!(DotTypes::Light, DotColors::ForegroundYellow ); }
pub fn fg_blue () { printdot!(DotTypes::Light, DotColors::ForegroundBlue ); }
pub fn fg_magenta () { printdot!(DotTypes::Light, DotColors::ForegroundMagenta ); }
pub fn fg_cyan () { printdot!(DotTypes::Light, DotColors::ForegroundCyan ); }
pub fn fg_white () { printdot!(DotTypes::Light, DotColors::ForegroundWhite ); }
pub fn fg_default () { printdot!(DotTypes::Light, DotColors::ForegroundDefault ); }
pub fn fg_light_black () { printdot!(DotTypes::Light, DotColors::ForegroundLightBlack ); }
pub fn fg_light_red () { printdot!(DotTypes::Light, DotColors::ForegroundLightRed ); }
pub fn fg_light_green () { printdot!(DotTypes::Light, DotColors::ForegroundLightGreen ); }
pub fn fg_light_yellow () { printdot!(DotTypes::Light, DotColors::ForegroundLightYellow ); }
pub fn fg_light_blue () { printdot!(DotTypes::Light, DotColors::ForegroundLightBlue ); }
pub fn fg_light_magenta() { printdot!(DotTypes::Light, DotColors::ForegroundLightMagenta); }
pub fn fg_light_cyan () { printdot!(DotTypes::Light, DotColors::ForegroundLightCyan ); }
pub fn fg_light_white () { printdot!(DotTypes::Light, DotColors::ForegroundLightWhite ); }
pub fn fg_light_default() { printdot!(DotTypes::Light, DotColors::ForegroundLightDefault); }
pub fn reset () { printdot!(DotTypes::Light, DotColors::Reset ); }
}
#[macro_export]
macro_rules! colodot {
($dot_type: expr, $dot_color: expr, $args: expr) => {
let data: &str = $args;
print!("\x1b[{};{}m{}", $dot_color as u8, $dot_type as u8, data);
};
($dot_type: expr, $dot_color: expr, $args: expr, $reset: expr) => {
{
let _force_to_bool: bool = $reset;
colodot!($dot_type, $dot_color, $args);
if _force_to_bool {
print!("{}", "\x1b[0m");
}
}
};
($dot_true_color: expr, $args: expr) => {
let _type = $dot_true_color as DotTrueColor;
print!("\x1b[38;2;{};{};{}m{}", _type.r, _type.g, _type.b, $args);
};
}
#[cfg(test)]
mod tests {
use crate::dot::{
*,
dot_defineds
};
#[test]
fn play_with_colors() {
red() ; println!("{}", "Hello, red!" );
green(); println!("{}", "Hello, green!");
blue() ; println!("{}", "Hello, blue!" );
light_magenta(); println!("{}", "Hello light magenta!");
reset();
}
#[test]
fn play_with_types() {
colodot!(DotTypes::Bold, DotColors::Yellow, "Hello, bold yellow!\n", true);
colodot!(DotTypes::Blink,DotColors::ForegroundBlue, "Hello, foreground blink blue!\n", true);
}
#[test]
fn play_with_lazys() {
println!("{}{}", *dot_defineds::FG_BLUE_COLOR, "Hello, world!"); reset();
}
#[test]
fn play_with_truecolor() {
colodot!(DotTrueColor{r: 31, g: 69, b: 100}, "Hello, world!\n");
}
}