#terminal-colors #terminal #detect #give #port #npm-package #details

supports-color

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

13 stable releases

3.0.0 Feb 4, 2024
2.1.0 Sep 20, 2023
2.0.0 Dec 16, 2022
1.3.1 Nov 5, 2022
1.1.1 Sep 22, 2021

#39 in Command-line interface

Download history 58496/week @ 2023-12-23 97973/week @ 2023-12-30 110285/week @ 2024-01-06 121146/week @ 2024-01-13 118064/week @ 2024-01-20 110199/week @ 2024-01-27 123198/week @ 2024-02-03 109727/week @ 2024-02-10 105170/week @ 2024-02-17 111146/week @ 2024-02-24 125177/week @ 2024-03-02 123680/week @ 2024-03-09 137790/week @ 2024-03-16 130495/week @ 2024-03-23 130243/week @ 2024-03-30 110344/week @ 2024-04-06

529,593 downloads per month
Used in 230 crates (39 directly)

Apache-2.0

11KB
186 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