1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
//! colorable is a library that makes printing colored output to the console easy. //! //! # Get started //! //! ## Adding colorable as a dependency //! //! ```toml //! [dependecies] //! colorable = "0.1.0" //! ``` //! That's the only dependency you need //! //! # Usage //! //! colorable allows you to style console output using [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code). //! It allows this for any types that implement `std::fmt::Display` or `std::fmt::Debug`. //! ## How to use on types that implement `std::fmt::Display` //! Basic example: //! ```rust //! use colorable::*; //! //! fn main() { //! println!("{}", 1.green()); //! println!("{}", 2.blue().bold()); //! println!("{}", 3.with_fg_color(124).italic()); //! } //! ``` //! This will produce a green `1`, a bold blue `2` and a red italic `3`. The `124` in the last line corresponds to the ANSI color code for this shade of red. //! You can also set the background of the output like so: //! ```rust //! use colorable::*; //! //! fn main() { //! println!("{}", 1.magenta().with_bg_color(3)); //! } //! ``` //! This will produce a magenta `3` on blue background. Currently setting the background //! only works through explicit color codes which you can find [here](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) //! ## How to use on types that implement `std::fmt::Debug` //! The API for using colors and styles on objects that implement `std::fmt::Debug` is exactly the same as it for `std::fmt::Display`, except that every //! method has a `_dbg` suffix. This is done to avoid name clashing on types that implement both `std::fmt::Debug` and `std::fmt::Display`. //! The example from above could look something like this: //! ```rust //! use colorable::*; //! //! fn main() { //! let v = vec![1, 2, 3]; //! println!("{:?}", v.yellow_dbg()); //! println!("{:?}", v.cyan_dbg().bold_dbg()); //! } //! ``` //! ## **NOTE** //! Neither the Colored<T> nor the ColoredDbg<T> type use any kind of formatting flags. This means that the formatting flags on something like this: //! ```rust //! use colorable::*; //! //! fn main() { //! println!("{:#?}", vec![1, 2, 3].dark_cyan_dbg()); //! } //! ``` //! will simply be ignored and the output won't be pretty printed. If you want to use formatting flags, you can do something like this: //! ```rust //! use colorable::*; //! //! fn main() { //! println!("{}", format!("{:#?}", vec![1, 2, 3]).dark_cyan()); //! } //! ``` mod colorable; pub use crate::colorable::*; #[cfg(test)] mod tests { use super::*; #[test] fn test() { println!("{}", 1.green()); println!("{}", 2.blue().bold()); println!("{}", 3.with_fg_color(124).italic()); println!("{}", 1.magenta().with_bg_color(4)); let v = vec![1, 2, 3]; println!("{:?}", v.yellow_dbg()); println!("{:?}", v.cyan_dbg().bold_dbg()); println!("{}", format!("{:#?}", vec![1, 2, 3]).dark_cyan()); println!("{:#?}", vec![1, 2, 3].dark_cyan_dbg()); } }