#color #string #term #ansi-term #term-painter


The most simple way to add true colors in your terminal

1 unstable release

Uses old Rust 2015

0.1.0 Sep 17, 2019

#7 in #term-painter

Download history 116/week @ 2023-10-29 80/week @ 2023-11-05 52/week @ 2023-11-12 135/week @ 2023-11-19 210/week @ 2023-11-26 96/week @ 2023-12-03 67/week @ 2023-12-10 81/week @ 2023-12-17 78/week @ 2023-12-24 27/week @ 2023-12-31 65/week @ 2024-01-07 59/week @ 2024-01-14 43/week @ 2024-01-21 24/week @ 2024-01-28 32/week @ 2024-02-04 31/week @ 2024-02-11

133 downloads per month
Used in 7 crates

MPL-2.0 license

1.5K SLoC



For use true colors in my repub, I published it. When original crate is updated to v1.3.0, this will be yanked maybe. (details in https://github.com/mackwic/colored/issues/6 )


Build Status Crates.io Crates.io

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();
    "bright colors are welcome as well".on_bright_blue().bright_red();
    "or any rgb color".true_color(171, 205, 239);
    "or any hexadecimal color".hex_color(0xabcdef);
    "or use colors from the palette".palette(36);
    "you can also make bold comments".bold();
    println!("{} {} {}", "or use".cyan(), "any".italic().yellow(), "string type".cyan());
    "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("blue").on_color("red");
    String::from("this also works!").green().bold();
    format!("{:30}", "format works as expected. This will be padded".blue());
    format!("{:.3}", "and this will be green but truncated to 3 chars".green());

How to use

Add this in your Cargo.toml:

colored = "1.8"

and add this to your lib.rs or main.rs:

    extern crate colored; // not needed in Rust 2018

    use colored::*;

    // test the example with `cargo run --example most_simple`
    fn main() {
        // TADAA!
        println!("{} {} !", "it".green(), "works".blue().bold());


  • Safe rust, easy to use, minimal dependencies, complete test suite
  • Respect the CLICOLOR/CLICOLOR_FORCE behavior (see the specs)
  • Respect the NO_COLOR behavior (see the specs)
  • Works on Linux, MacOS, and Windows (Powershell)


  • black
  • red
  • green
  • yellow
  • blue
  • magenta (or purple)
  • cyan
  • white

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. Any 8-bit palette color: use palette(u8). Super simple. Any RGB color: use true_color(u8, u8, u8). Really easy. Any hexadecimal color: use hex_color(0xABCDEF). Far from difficult.


  • bold
  • underline
  • italic
  • dimmed
  • reversed
  • blink
  • hidden
  • strikethrough

You can clear color and style anytime by using normal() or clear()

Advanced Control:

Dynamic color from str

As Color implements FromStr, From<&str>, and From<String>, you can easily cast a string into a color like that:

// the easy way
"blue string yo".color("blue");

// this will default to white
"white string".color("zorglub");

// the safer way via a Result
let color_res : Result<Color, ()> = "zorglub".parse();
"red string".color(color_res.unwrap_or(Color::Red));
Colorization control

If you want to disable any coloring at compile time, you can simply do so by using the no-color feature.

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`
dumb_terminal = ["colored/no-color"]

You can use have even finer control by using the colored::control::set_override method.


  • 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.


Mozilla Public License 2.0. See the LICENSE file at the root of the repository.

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.



~23K SLoC