| Crates.io | libtermcolor |
| lib.rs | libtermcolor |
| version | 1.1.0 |
| created_at | 2024-05-17 17:39:59.002965+00 |
| updated_at | 2024-05-18 20:31:55.837807+00 |
| description | A simple Ansi Color Library for C/C++ and Rust |
| homepage | |
| repository | https://github.com/Noriskky/libTermColor |
| max_upload_size | |
| id | 1243516 |
| size | 11,326 |
🚀 LTC provides a convenient way to use Color in the Terminal using C/C++ & Rust
When you want to use it in your project it's really Easy just get the newest libtermcolor.h from the Releases Tab.
Then put this file in your src/ folder and include the Libary with
#include "libtermcolor.h"
If you have it another location have to replace libtermcolor.h with your path to the .h file.
For just you have to add it the following in your Cargo.toml:
[dependencies]
libtermcolor = "<version>"
or use the following command:
cargo add libtermcolor
If you just want an example just can look at for C/C++ example/main.cpp and example.rs for Rust.
colors::RED.regular
^ ^
| |
Color TYPE
use libtermcolor; <-- Import the Libary
libtermcolor::colors::red().regular
^ ^
| |
Color TYPE
Color: This specifies what color you want to use as List can be found at #Colors or by typing colors:: and pressing CTRL + SPACE in your code.
Type: The type says if it should be:
[!NOTE] Reset can also be used with:
colors::RESET
You can also get The Colors by string with the following:
colors::getColorCode("RED", "REGULAR")
^ ^
| |
Color Type
libtermcolor::colors::get_color_code("RED", "REGULAR");
^ ^
| |
Color Type
[!NOTE] This capitalization does not matter.

I have written a quick example that will output every Color + It's states:
#include <iostream>
#include "libtermcolor.h"
int main() {
for (const auto& pair : colors::color_map) {
std::cout << pair.second.background << pair.first << colors::RESET << ":\n";
std::cout << colors::BLACK.background << " Regular: " << colors::RESET << pair.second.regular << pair.first << pair.second.reset << std::endl;
std::cout << colors::BLACK.background << " Bold: " << colors::RESET << pair.second.bold << pair.first << pair.second.reset << std::endl;
std::cout << colors::BLACK.background << " Underline: " << colors::RESET << pair.second.underline << pair.first << pair.second.reset << std::endl;
std::cout << colors::BLACK.background << " Background: " << colors::RESET << pair.second.background << pair.first << pair.second.reset << std::endl;
}
return 0;
}
This code can also be found at example/main.cpp.
use libtermcolor;
fn main() {
for (color_name, color_attributes) in libtermcolor::colors::COLOR_MAP.iter() {
println!("{}{}{}:", color_attributes.background, color_name, libtermcolor::colors::reset());
println!(" Regular: {}{}{}{}", color_attributes.regular, color_name, color_attributes.reset, libtermcolor::colors::reset());
println!(" Bold: {}{}{}{}", color_attributes.bold, color_name, color_attributes.reset, libtermcolor::colors::reset());
println!(" Underline: {}{}{}{}", color_attributes.underline, color_name, color_attributes.reset, libtermcolor::colors::reset());
println!(" Background: {}{}{}{}", color_attributes.background, color_name, color_attributes.reset, libtermcolor::colors::reset());
}
}
This code can also be found at example/main.rs.
- BLACK
- BRIGHT_BLACK
- RED
- BRIGHT_RED
- GREEN
- BRIGHT_GREEN
- YELLOW
- BRIGHT_YELLOW
- BLUE
- BRIGHT_BLUE
- MAGENTA
- BRIGHT_MAGENTA
- CYAN
- BRIGHT_CYAN
- WHITE
- BRIGHT_WHITE
You can use the example to test your Code.
You can compile and test the example with the following command:
make clean
make build
./output/main
cd example
cargo build
cargo build