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

Overview

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.");
}
You might also like...
Rust library to convert RGB 24-bit colors into ANSI 256 (8-bit) color codes with zero dependencies and at compile-time.
Rust library to convert RGB 24-bit colors into ANSI 256 (8-bit) color codes with zero dependencies and at compile-time.

rgb2ansi256 rgb2ansi256 is a small Rust library to convert RGB 24-bit colors into ANSI 256 (8-bit) color codes with zero dependencies and const fn. Th

An abstract, safe, and concise color conversion library for rust nightly This requires the feature adt_const_params

colortypes A type safe color conversion library This crate provides many methods for converting between color types. Everything is implemented abstrac

A rust crate for working with colors and color spaces.
A rust crate for working with colors and color spaces.

Color Art A rust crate for working with colors and color spaces. Documentation See Color Art. Usage Add Dependency [dependencies] color-art = "0.2" Co

Convert your favorite images and wallpapers with your favorite color palettes/themes
Convert your favorite images and wallpapers with your favorite color palettes/themes

dipc doprz' image palette converter Convert your favorite images and wallpapers with your favorite color palettes/themes Color Palettes/Themes catppuc

🖥  A feature rich terminal UI file transfer and explorer with support for SCP/SFTP/FTP/S3
🖥 A feature rich terminal UI file transfer and explorer with support for SCP/SFTP/FTP/S3

🖥 A feature rich terminal UI file transfer and explorer with support for SCP/SFTP/FTP/S3

Parse hex colors to tui::style::Color

Color - Tui Parse hex colors to tui rgb colors #c3f111 - Color::Rgb(195,241,17) Note that the indexed colors are NOT HEX #142 - Color::Indexed(142)

Tiny color conversion library for TUI application builders
Tiny color conversion library for TUI application builders

Definition of ANSI, RGB and HSL color types and all the conversions between them. There are many other color conversion crates. This one may be useful

A command line tool for playing with color gradients
A command line tool for playing with color gradients

gradient A command-line tool for playing with color gradients. Features Lots of preset gradients. Custom gradient. Read gradients from SVG & GIMP grad

dye is a tool to easily color text in shell.
dye is a tool to easily color text in shell.

Dye dye is a tool to easily color text in shell. Usage See the gif below to see these commands in action. echo $(dye --red WARN) This tool will knock

Comments
  • `atty` is potentially unsound, not very alive and should be replaced with `is-terminal`

    `atty` is potentially unsound, not very alive and should be replaced with `is-terminal`

    Some links explaining the problem

    • https://github.com/softprops/atty/pull/51
    • https://github.com/clap-rs/clap/pull/4249#discussion_r1029107456
    • https://github.com/rustsec/advisory-db/issues/1457

    I can prepare a pull request if you like

    opened by pacak 2
  • Various improvements

    Various improvements

    This PR removes some string allocations in the supports_color function.

    I originally wanted to use Result::as_deref for this, but since I wasn't sure what the minimum supported Rust version is, and Result::as_deref is only available since 1.47, I just wrote a helper function instead.

    Other changes:

    • I removed min since it is guaranteed to be 0 everywhere where it is used
    • I reordered some code paths to do less work by returning earlier if FORCE_COLOR or NO_COLOR is set
    • I fixed the tests, which were flaky; cargo runs tests in parallel, which does not work properly if multiple tests read and write environment variables. The solution was to add a lock that ensures the tests run sequentially.
    opened by Aloso 2
  • Ignore unit tests on GH action

    Ignore unit tests on GH action

    I just realized that the unit-tests is much trickier than it looks.

    1. GH action does not play nice with atty::is. Unit-tests couldn't be run in CI reliably.
    2. Cargo run tests in parallel by default, and this affects reliability of the unit-test. Unit-test should be run with cargo test -- --test-threads=1. Mght want to put this information somewhere. Another option is to remove unit-test altogether.
    opened by dswij 1
Releases(v1.3.1)
Owner
Kat Marchán
rustacean 🦀, @NuGet team 🍫. Formerly @npmjs 😩
Kat Marchán
Test whether a given stream is a terminal

is-terminal Test whether a given stream is a terminal is-terminal is a simple utility that answers one question: Is this a terminal? A "terminal", als

Dan Gohman 19 Dec 31, 2022
Gives custom drugs to your terminal 💊

Linux on drugs ?? Gives custom drugs to your terminal ?? Output random colors really fast Installation ?? Arch Linux Linux on drugs is in the AUR yay

Skwal 3 Sep 10, 2022
Enhance Rust errors with file and line details using the `#[wherr]` macro for clearer debugging.

wherr Crate Discuss wherr on Hacker News Enhance Rust's ? operator by appending file and line number details to errors, simplifying the debugging proc

Joel Jakobsson 49 Sep 6, 2023
A Rust library for evaluating log4j substitution queries in order to determine whether or not malicious queries may exist.

log4j_interpreter A Rust library for evaluating log4j substitution queries in order to determine whether or not malicious queries may exist. Limitatio

Fastly 22 Nov 7, 2022
Sero is a web server that allows you to easily host your static sites without pain. The idea was inspired by surge.sh but gives you full control.

sero Lightning-fast, static web publishing with zero configuration and full control ?? Table Of Contents ?? Table Of Contents ?? Tools ❓ About The Pro

Dmitry Miasnenko 6 Nov 13, 2023
Detects Linux input, notifies with bell sound

Keypress Notifier keypress-notifier는 리눅스에서 동작하는 입력 이벤트 감지 및 벨 소리 알림 프로젝트입니다. 소개 keypress-notifier는 Rust 언어로 개발되었으며, 키패드, 마우스 등의 입력 이벤트를 감지하고, 벨 소리로 사용

인준 4 Feb 15, 2024
A dead simple ANSI terminal color painting library for Rust.

yansi A dead simple ANSI terminal color painting library for Rust. use yansi::Paint; print!("{} light, {} light!", Paint::green("Green"), Paint::red(

Sergio Benitez 169 Dec 25, 2022
A clock app in terminal written in Rust, supports local clock, timer and stopwatch.

clock-tui (tclock) A clock app in terminal. It support the following modes: Clock Timer Stopwatch Countdown Usage Install Install excutable by cargo:

Jimmy 14 Dec 20, 2022
Blazingly fast interpolated LUT generator and applicator for arbitrary and popular color palettes.

lutgen-rs A blazingly fast interpolated LUT generator and applicator for arbitrary and popular color palettes. Theme any image to your dekstop colorsc

null 12 Jun 16, 2023
`ls` alternative with useful info and a splash of color 🎨

?? Natls ?? Why Natls? Showing file permissions Showing file size Showing the date that the file was modified last Showing the user that the file belo

Will 1.2k Dec 19, 2022