#terminal #color #account

supports-color

Detects whether a terminal supports color, and gives details about that support

10 stable releases

1.3.1 Nov 5, 2022
1.3.0 Oct 4, 2021
1.1.1 Sep 22, 2021

#34 in #terminal

Download history 79748/week @ 2022-08-19 82622/week @ 2022-08-26 87148/week @ 2022-09-02 96994/week @ 2022-09-09 71385/week @ 2022-09-16 85694/week @ 2022-09-23 85915/week @ 2022-09-30 96315/week @ 2022-10-07 104373/week @ 2022-10-14 83377/week @ 2022-10-21 79394/week @ 2022-10-28 67169/week @ 2022-11-04 80114/week @ 2022-11-11 71533/week @ 2022-11-18 64573/week @ 2022-11-25 54195/week @ 2022-12-02

283,159 downloads per month
Used in 67 crates (14 directly)

Apache-2.0

10KB
165 lines

Detects whether a terminal supports color, and gives details about that support. It takes into account the NO_COLOR environment variable.

This crate is a Rust port of @sindresorhus' NPM package by the same name.

Example

use supports_color::Stream;

if let Some(support) = supports_color::on(Stream::Stdout) {
    if support.has_16m {
        println!("16 million (RGB) colors are supported");
    } else if support.has_256 {
        println!("256 colors are supported.");
    } else if support.has_basic {
        println!("Only basic ANSI colors are supported.");
    }
} else {
    println!("No color support.");
}

lib.rs:

Detects whether a terminal supports color, and gives details about that support. It takes into account the NO_COLOR environment variable.

This crate is a Rust port of @sindresorhus' NPM package by the same name.

Example

use supports_color::Stream;

if let Some(support) = supports_color::on(Stream::Stdout) {
    if support.has_16m {
        println!("16 million (RGB) colors are supported");
    } else if support.has_256 {
        println!("256-bit colors are supported.");
    } else if support.has_basic {
        println!("Only basic ANSI colors are supported.");
    }
} else {
    println!("No color support.");
}

Dependencies

~39KB