colorize
A set of Rust macros to assist in turning text into colors for printing on the terminal.
Purpose
As I was working with another command line utility, I wanted the ability to convert regular text into ANSI color formatted text more easily, so I wrote a series of macros to help with formatting and/or printing that could be reusable.
Adding
You can add the macros to your project by using cargo
or adding colorize-macros
to your depedencies.
[]
= "^0.8"
Usage
use ;
// println "Hello world" in bold green
print_color!;
// Returns "Hello" in italic blue and "World" underlined in magenta
let color_string = colorize!;
assert_eq!;
// Add a format token to multiple inputs using `=>`
// The below example will produce "Hello" with a green foreground,
// "world" with a blue background, both in bold.
let color_string = colorize!;
assert_eq!;
use PathBuf;
let user_path = from;
let pretty_path = colorize!;
assert_eq!;
print_color!;
See the colorize macro docs for further style specs.
Development
- Add background color
- Add ability to format multiple arguments with the same input (ie
colorize!("{}, {}", b => "Hello", Fg-> "world")
where "Hello" and "world" are both bold but "world" is the only word that's green) - Integrate a color set of log macros from the log crate
Special Thanks
This crate was originally inspired by the row macro in prettytable.