Skip to content

Latest commit

 

History

History
77 lines (55 loc) · 1.54 KB

colored.md

File metadata and controls

77 lines (55 loc) · 1.54 KB

Colored

colored is a Rust crate for creating colored CLI applications.

colored can use the environment variables: NO_COLOR and CLICOLOR and it's companion CLICOLOR_FORCE.

But how would that work? - which setting wins.

  • CLICOLOR enables coloring
  • CLICOLOR enabled and enforces coloring
  • NO_COLOR disables coloring

I made a quick experiment based on the example from the colored documentation.

$ mkdir colored
$ cargo init colored
$ cd $_

Edit the Cargo.toml file.

[dependencies]
colored = "2"

Install/update dependencies.

$ cargo update

Edit our example (src/main.rs)

use colored::*;

fn main() {
    println!("{} {} !", "Hello,".green(), " World!".red().bold());
}

Try it out:

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/colored`
Hello,  World! !

And you should see colorful output.

$ NO_COLOR=1 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/colored`
Hello,  World!

And you should not see colorful output.

❯ NO_COLOR=1 CLICOLOR_FORCE=1 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/colored`
Hello,  World! !

And hey, what do you know, $CLICOLOR_FORCE wins over $NO_COLOR.

Resources and References

  1. crates.io: colored
  2. NO_COLOR specification
  3. CLI_COLORS specification