term_color_support

Crates.ioterm_color_support
lib.rsterm_color_support
version0.1.1
sourcesrc
created_at2024-05-21 05:30:08.705934
updated_at2024-05-22 06:15:32.307648
descriptionDetermine whether a terminal supports color or not, and identify the level of color support.
homepage
repositoryhttps://github.com/itsmenirajpaudel/term-color-support
max_upload_size
id1246434
size56,622
Niraj Paudel (itsmenirajpaudel)

documentation

README

Term Color Support

Description

Determine whether a terminal supports color or not, and if it supports color, identify the level of color support available.

Features

  • Detect if the terminal supports color.
  • Identify the level of color support (e.g., no color, basic 16 colors, 256 colors, true color).

Installation

Prerequisites

  • Rust (Ensure you have Rust and Cargo installed)

Adding as a Dependency

To use this package, add the following to your Cargo.toml:

[dependencies]
term_color_support = "0.1.0"  # Replace with the latest version

Usage

use term_color_support::ColorSupport;
fn main() {
    // Detect and print color support for stdout
    println!("Color support for stdout: {:?}", ColorSupport::stdout());

    // Detect and print color support for stderr
    println!("Color support for stderr: {:?}", ColorSupport::stderr());
}

The output of the above code will be something like this:

Color support for stdout: ColorInfo { level: TrueColor, has_basic: true, has_256: true, has_16m: true }
Color support for stderr: ColorInfo { level: TrueColor, has_basic: true, has_256: true, has_16m: true }

API

Structs

ColorInfo

pub struct ColorInfo {
    /// The color support level.
    pub level: ColorSupportLevel,
    /// Indicates if basic color support is available.
    pub has_basic: bool,
    /// Indicates if 256-color support is available.
    pub has_256: bool,
    /// Indicates if true color support (16 million colors) is available.
    pub has_16m: bool,
}

ColorSupportLevel

pub enum ColorSupportLevel {
    /// No color support.
    NoColor,
    /// Basic color support.
    Basic,
    /// Support for 256 colors.
    Colors256,
    /// True color support.
    TrueColor,
}

Examples

For detailed examples of how to use the package, including more complex use cases and scenarios, you can refer to the main.rs file in the src/bin directory. A simple example is provided there.

Contributing

Guidelines for contributing to Term Color Support:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature-name).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add some feature').
  5. Push to the branch (git push origin feature/your-feature-name).
  6. Open a Pull Request.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Acknowledgements

Term Color Support was inspired by the npm package supports-color, which is used to detect whether a terminal supports color. The concepts of Term Color Support are influenced by supports-color.

We are thankful to the maintainers of supports-color, Sindre Sorhus and Josh Junon, for their contribution to the open-source community.

Contact

For support or questions, you can contact me via:

Commit count: 15

cargo fmt