Crates.io | term_color_support |
lib.rs | term_color_support |
version | 0.1.1 |
source | src |
created_at | 2024-05-21 05:30:08.705934 |
updated_at | 2024-05-22 06:15:32.307648 |
description | Determine whether a terminal supports color or not, and identify the level of color support. |
homepage | |
repository | https://github.com/itsmenirajpaudel/term-color-support |
max_upload_size | |
id | 1246434 |
size | 56,622 |
Determine whether a terminal supports color or not, and if it supports color, identify the level of color support available.
To use this package, add the following to your Cargo.toml
:
[dependencies]
term_color_support = "0.1.0" # Replace with the latest version
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 }
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,
}
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.
Guidelines for contributing to Term Color Support:
git checkout -b feature/your-feature-name
).git commit -m 'Add some feature'
).git push origin feature/your-feature-name
).This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
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.
For support or questions, you can contact me via:
Email: itsmenirajpaudel@gmail.com
LinkedIn: itsmenirajpaudel
Website: https://nirajpaudel.me