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
:
[]
= "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
ColorSupportLevel
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:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature-name
). - 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:
- Email: itsmenirajpaudel@gmail.com
- LinkedIn: itsmenirajpaudel
- Website: https://nirajpaudel.me