#[macro_use]
pub mod raw;
pub mod colors;
pub mod writer;
macro_rules! build_colored {
( $( $color:tt | $name:ident | $name2:ident )+ ) => {
#[macro_export]
macro_rules! color_args {
$(
($name, $s:expr) => {
format_args!(
"{}{}{}",
concat!(
raw_color!(start),
$color,
raw_color!(end_color),
),
$s,
raw_color!(end),
)
};
($name, bold, $s:expr) => {
format_args!(
"{}{}{}{}",
concat!(
raw_color!(start),
$color,
raw_color!(end_color),
),
raw_color!(bold),
$s,
raw_color!(end),
)
};
($name2, $s:expr) => { color_args!($name, $s) };
($name2, bold, $s:expr) => { color_args!($name, bold, $s) };
)+
}
#[macro_export]
macro_rules! color {
$(
($name, $s:expr) => {
concat!(
concat!(
raw_color!(start),
$color,
raw_color!(end_color),
),
$s,
raw_color!(end),
)
};
($name, bold, $s:expr) => {
concat!(
concat!(
raw_color!(start),
$color,
raw_color!(end_color),
),
raw_color!(bold),
$s,
raw_color!(end),
)
};
($name2, $s:expr) => { color_args!($name, $s) };
($name2, bold, $s:expr) => { color_args!($name, bold, $s) };
)+
}
#[macro_export]
macro_rules! color_format {
$(
($name, $s:expr) => {
format!("{}", color_args!($name, $s))
};
($name2, $s:expr) => { color!($name, $s) };
($name, bold, $s:expr) => {
format!("{}", color_args!($name, bold, $s))
};
($name2, bold, $s:expr) => { color!($name, bold, $s) };
)+
}
}
}
build_colored! (
"30" | black | BLACK
"31" | red | RED
"32" | green | GREEN
"33" | yellow | YELLOW
"34" | blue | BLUE
"35" | magenta | MAGENTA
"36" | cyan | CYAN
"37" | white | WHITE
"90" | bright_black | BRIGHT_BLACK
"91" | bright_red | BRIGHT_RED
"92" | bright_green | BRIGHT_GREEN
"93" | bright_yellow | BRIGHT_YELLOW
"94" | bright_blue | BRIGHT_BLUE
"95" | bright_magenta | BRIGHT_MAGENTA
"96" | bright_cyan | BRIGHT_CYAN
"97" | bright_white | BRIGHT_WHITE
);
use std::fmt::Arguments;
use std::io::Write;
use writer::cluColorWriter;
use std::hash::Hash;
use std::fmt::Display;
use std::fmt::Debug;
use std::io;
#[allow(non_camel_case_types)]
pub trait cluColor: Debug + Display + Eq + Hash + Ord + PartialEq + PartialOrd {
fn raw_color<'a>() -> &'a str;
fn raw_color_b<'a>() -> &'a [u8];
fn name<'a>() -> &'a str;
#[inline]
fn writer() -> cluColorWriter<Self> where Self: Sized {
cluColorWriter::<Self>::new()
}
#[inline]
fn string_as<'a, A: AsRef<str>>(asref: A) -> String {
Self::string(asref.as_ref())
}
#[inline]
fn stringn_as<'a, A: AsRef<str>>(asref: A) -> String {
Self::stringn(asref.as_ref())
}
fn string<'a>(str: &'a str) -> String;
fn string_fmt<'a>(fmt: Arguments<'a>) -> String;
fn stringn<'a>(str: &'a str) -> String;
fn stringn_fmt<'a>(fmt: Arguments<'a>) -> String;
#[inline]
fn write_as<'a, A: AsRef<[u8]>>(w: &mut Write, asref: A) -> io::Result<()> {
Self::write(w, asref.as_ref())
}
#[inline]
fn writen_as<'a, A: AsRef<[u8]>>(w: &mut Write, asref: A) -> io::Result<()> {
Self::writen(w, asref.as_ref())
}
fn write<'a>(w: &mut Write, buf: &'a [u8]) -> io::Result<()>;
fn write_str<'a>(w: &mut Write, str: &'a str) -> io::Result<()>;
fn write_fmt<'a>(w: &mut Write, fmt: Arguments<'a>) -> io::Result<()>;
fn writen<'a>(w: &mut Write, buf: &'a [u8]) -> io::Result<()>;
fn writen_str<'a>(w: &mut Write, str: &'a str) -> io::Result<()>;
fn writen_fmt<'a>(w: &mut Write, fmt: Arguments<'a>) -> io::Result<()>;
fn with_color_fmt<'a, F: Fn(&Arguments) -> T, T: 'a>(args: Arguments<'a>, function: F) -> T;
fn once_with_color_fmt<'a, F: FnOnce(&Arguments) -> T, T: 'a>(args: Arguments<'a>, function: F) -> T;
fn mut_with_color_fmt<'a, F: FnMut(&Arguments) -> T, T: 'a>(args: Arguments<'a>, function: F) -> T;
}
#[macro_export]
macro_rules! write_color {
( $write:expr, $color:tt, $( $arg:tt )* ) => {
$color::write_fmt($write, format_args!( $( $arg )* ))
};
}
#[macro_export]
macro_rules! writen_color {
( $write:expr, $color:tt, $( $arg:tt )* ) => {
$color::writen_fmt($write, format_args!( $( $arg )* ))
};
}