2
0
mirror of https://github.com/xvxx/phd synced 2024-11-10 13:10:23 +00:00
phd/src/color.rs

43 lines
881 B
Rust
Raw Normal View History

2020-01-15 20:50:31 +00:00
//! Cheesy way to easily wrap text in console colors.
//! Example:
//! ```
//! use phd::color;
//! println!("{}Error: {}{}", color::Red, "Something broke.", color::Reset);
//! ```
2020-01-04 23:46:12 +00:00
use std::fmt;
macro_rules! color {
($t:ident, $code:expr) => {
2020-01-15 20:50:31 +00:00
#[allow(missing_docs)]
2020-01-04 23:46:12 +00:00
pub struct $t;
impl fmt::Display for $t {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "\x1b[{}m", $code)
}
}
};
}
color!(Black, 90);
color!(Red, 91);
color!(Green, 92);
color!(Yellow, 93);
color!(Blue, 94);
color!(Magenta, 95);
color!(Cyan, 96);
color!(White, 97);
2020-01-05 00:24:22 +00:00
color!(DarkBlack, 30);
color!(DarkRed, 31);
color!(DarkGreen, 32);
color!(DarkYellow, 33);
color!(DarkBlue, 34);
color!(DarkMagenta, 35);
color!(DarkCyan, 36);
color!(DarkWhite, 37);
2020-01-04 23:46:12 +00:00
color!(Reset, 0);
color!(Bold, 1);
color!(Underline, 4);