no_color 0.2.0

Detect NO_COLOR environment variable.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 11.38 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 116.51 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sitkevij/no_color
    8 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sitkevij

no_color

no_color is a zero dependency rust library for NO_COLOR environment variable detection.

Crates.io Crates.io GitHub repo size main docs.rs License

About

From no-color.org:

An increasing number of command-line software programs output text with ANSI color escape codes by default. While some developers and users obviously prefer seeing these colors, many users don’t. Unfortunately, every new piece of software seems to have a different way of disabling colored text output and some software has no way at all.

Accepting the futility of trying to reverse this trend, an informal standard is hereby proposed:

All command-line software which outputs text with ANSI color added should check for the presence of a NO_COLOR environment variable that, when present (regardless of its value), prevents the addition of ANSI color.

By adopting this standard, users that prefer to have plain, non-colored text output can set one environment variable in their shell to have it automatically affect all supported software.

Usage

no_color is a library crate which works with Cargo.

Add to Cargo.toml

To use, add the following to your Cargo.toml dependencies section:

[dependencies]
no_color = "0.2"

or use cargo add:

cargo add no_color

Implementing Code

Suggested updates to your rust code as below:

extern crate no_color;

use no_color::*;

fn main() {
    println!(
        "Environment variable NO_COLOR {0} found. Now do something.",
        {
            if is_no_color() {
                "is"
            } else {
                "is NOT"
            }
        }
    );
}