Colors.hpp is a simple header for C++ for stylish text in terminal created for study stream manipulators.
The library uses ANSI escape sequences via stream manipulators. Now, Windows is supported through its API, to see what features are available, see the methods list below.
Just add the colors.hpp from include/colors/colors.hpp file to your project's include folder.
- Example with g++
g++ test.cpp -o build/test -I include/
All the stream manipulators are defined under the colors namespace, so just #include the header in your file as shown below:
#include <iostream>
#include <colors/colors.hpp>
int main() {
std::cout << colors::bold << colors::red << colors::on_white << "A coloful message!" << colors::reset << "\n";
return 0
}Important 1: If your project doesn't have a include folder, use the #include "colors.hpp" directive instead!
Important 2: You must not forget to use colors::reset, otherwise, the colors and styles will be applied to the next output! In windows cmd, the colors are applied even if the program has already ended, so be sure to use this manipulator!
There are four types of manipulator defined in the library:
- Style: changes the text decoration style;
- Foreground: changes the text color itself;
- Background: changes the text background color;
Note 1: Some terminals don't support some of this features, like blinking!
Note 2: Windows doesn't support these manipulators!
colors::boldcolors::faintcolors::italiccolors::underlinecolors::blinkcolors::reversecolors::invisiblecolors::strikethrough
colors::greycolors::redcolors::greencolors::yellowcolors::bluecolors::magentacolors::cyancolors::whitecolors::bright_greycolors::bright_redcolors::bright_greencolors::bright_yellowcolors::bright_bluecolors::bright_magentacolors::bright_cyancolors::bright_white
You can find the color codes here.
Note: Windows doesn't support this manipulator!
colors::color<COLOR_CODE>
Note: Not all terminals supports this feature!
Note 2: Windows doesn't support this manipulator!
colors::color<RED, GREEN, BLUE>
colors::on_greycolors::on_redcolors::on_greencolors::on_yellowcolors::on_bluecolors::on_magentacolors::on_cyancolors::on_whitecolors::on_bright_greycolors::on_bright_redcolors::on_bright_greencolors::on_bright_yellowcolors::on_bright_bluecolors::on_bright_magentacolors::on_bright_cyancolors::on_bright_white
You can find the color codes here.
Note: Windows doesn't support this manipulator!
colors::on_color<COLOR_CODE>
Note 1: Not all terminals supports this feature!
Note 2: Windows doesn't support this manipulator!
colors::on_color<RED, GREEN, BLUE>
Thanks for visiting my repository!
