Coloring terminal so simple, you already know how to do it!
"this is blue".blue; "this is red".red; "this is red on blue".red.on_blue; "this is also red on blue".on_blue.red; "you can use truecolor values too!".truecolor; "background truecolor also works :)".on_truecolor; "bright colors are welcome as well".on_bright_blue.bright_red; "you can also make bold comments".bold; println!; "or change advice. This is red".yellow.blue.red; "or clear things up. This is default color and style".red.bold.clear; "purple and magenta are the same".purple.magenta; "and so are normal and clear".normal.clear; "you can specify color by string".color.on_color; Stringfrom.green.bold; format!; format!;
How to use
Add this in your
 = "2"
and add this to your
extern crate colored; // not needed in Rust 2018+ use *; // test the example with `cargo run --example most_simple`
- Safe rust, easy to use, minimal dependencies, complete test suite
- Respect the
CLICOLOR_FORCEbehavior (see the specs)
- Respect the
NO_COLORbehavior (see the specs)
- Works on Linux, MacOS, and Windows (Powershell)
- magenta (or purple)
Bright colors: prepend the color by
bright_. So easy.
Background colors: prepend the color by
on_. Simple as that.
Bright Background colors: prepend the color by
on_bright_. Not hard at all.
Colored has support for truecolors where you can specify any arbitrary rgb value.
This feature will only work correctly in terminals which support true colors (i.e. most modern terminals).
You can check if your terminal supports true color by checking the value of the environment variable
$COLORTERM on your terminal. A value of
24bit indicates that it will work.
You can clear color and style anytime by using
Dynamic color from str
From<String>, you can easily cast a string into a color like that:
// the easy way "blue string yo".color; // this will default to white "white string".color; // the safer way via a Result let color_res : = "zorglub".parse; "red string".color;
If you want to disable any coloring at compile time, you can simply do so by
For example, you can do this in your
Cargo.toml to disable color in tests:
 # this effectively enable the feature `no-color` of colored when testing with # `cargo test --feature dumb_terminal` = ["colored/no-color"]
You can use have even finer control by using the
- More tests ?: We always welcome more tests! Please contribute!
This library wouldn't have been the same without the marvelous ruby gem colored.
Thanks for the ansi_term crate for providing a reference implementation, which greatly helped making this crate output correct strings.
Minimum Supported Rust Version (MSRV)
The current MSRV is
1.63, which is checked and enforced automatically via CI. This version may change in the future in minor version bumps, so if you require a specific Rust version you should use a restricted version requirement such as
In non legal terms it means that:
- if you fix a bug, you MUST give me the code of the fix (it's only fair)
- if you change/extend the API, you MUST give me the code you changed in the files under MPL2.
- you CAN'T sue me for anything about this code
- apart from that, you can do almost whatever you want. See the LICENSE file for details.