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::bold
colors::faint
colors::italic
colors::underline
colors::blink
colors::reverse
colors::invisible
colors::strikethrough
colors::grey
colors::red
colors::green
colors::yellow
colors::blue
colors::magenta
colors::cyan
colors::white
colors::bright_grey
colors::bright_red
colors::bright_green
colors::bright_yellow
colors::bright_blue
colors::bright_magenta
colors::bright_cyan
colors::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_grey
colors::on_red
colors::on_green
colors::on_yellow
colors::on_blue
colors::on_magenta
colors::on_cyan
colors::on_white
colors::on_bright_grey
colors::on_bright_red
colors::on_bright_green
colors::on_bright_yellow
colors::on_bright_blue
colors::on_bright_magenta
colors::on_bright_cyan
colors::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!