Skip to content

Noriskky/libTermColor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LTC - libTermColor

🚀 LTC provides a convenient way to use Color in the Terminal using C/C++ & Rust

C Badge C++ Badge Rust Badge

Installation

C/C++:

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.

Rust:

For Rust you have to add it the following in your Cargo.toml:

[dependencies]
libtermcolor = "<version>"

or use the following command:

cargo add libtermcolor

How to Use?

If you just want an example just can look at for C/C++ example/main.cpp and example.rs for Rust.

Basic Usage

C/C++

colors::RED.regular
         ^     ^
         |     |
       Color TYPE

Rust

use libtermcolor::colors; <-- Import the Libary

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:

  • Bold
  • Underline
  • Background (This is for changing Background Color)
  • Reset (This will reset the effect of before specified Colors)

Note

Reset can also be used with:

colors::RESET

By String

You can also get The Colors by string with the following:

C/C++

colors::getColorCode("RED", "REGULAR")
                       ^        ^
                       |        |
                     Color    Type

Rust

colors::get_color_code("RED", "REGULAR");
                         ^        ^
                         |        |
                       Color     Type

Note

The capitalization does not matter.

Example

Screenshot of Example

I have written a quick example that will output every Color + It's states:

C/C++

#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.

Rust

use libtermcolor::colors;

fn main() {
    for (color_name, color_attributes) in colors::COLOR_MAP.iter() {
        println!("{}{}{}:", color_attributes.background, color_name, colors::reset());
        println!("  Regular:    {}{}{}{}", color_attributes.regular, color_name, color_attributes.reset, colors::reset());
        println!("  Bold:       {}{}{}{}", color_attributes.bold, color_name, color_attributes.reset, colors::reset());
        println!("  Underline:  {}{}{}{}", color_attributes.underline, color_name, color_attributes.reset, colors::reset());
        println!("  Background: {}{}{}{}", color_attributes.background, color_name, color_attributes.reset, colors::reset());
    }
}

This code can also be found at example/main.rs.

Colors

- BLACK
- BRIGHT_BLACK
- RED
- BRIGHT_RED
- GREEN
- BRIGHT_GREEN
- YELLOW
- BRIGHT_YELLOW
- BLUE
- BRIGHT_BLUE
- MAGENTA
- BRIGHT_MAGENTA
- CYAN
- BRIGHT_CYAN
- WHITE
- BRIGHT_WHITE

How to Contribute

You can use the example to test your Code.

Compile Example

You can compile and test the example with the following command:

C/C++

make clean
make build
./output/main

Rust

cd example
cargo build

Compile Rust Libary

cargo build