ColorConsoleLib is a library that adds text coloring capabilities to the C++ standard output and error streams (cout/wcout and cerr/wcerr).
ColorConsoleLib provides compatible replacements for the C++ standard cout, cerr, wcout and wcerr output streams in the ColorConsole namespace that add text coloring capabilities by accepting Colors to the insertion operator (<<
).
#include "ColorConsole.hpp"
using namespace ColorConsole;
int main( int argc, const char* argv[] )
{
cout << Color::FG_LIGHT_BLUE << "Hello World!" << endl;
return 0;
}
There are 16 foreground Colors (which names start with FG_
) that can be mixed with 17 background Colors (which names start with BG_
) using the OR operation (|
).
Note:
The background Color
FG_BLACK
interpretation depends on the terminal. Some interpret it as black, others as transparent (showing the underlying console color).The background Color
FG_NONE
interpretation depends on the terminal. Some interpret it as transparent (showing the underlying console color), others as black.
The special Color RESET
can be used to return the console to the original "non-colored" mode.
Alternatively, the set_color() member function can be used, which behaves just like inserting a Color in the stream.
- CMake (≥ v3.13, tested with v3.17.2)
- CppUTest [Optional, not needed if tests are disabled] (tested with v3.9.alpha0)
- On Windows:
- A C/C++ compiler, either:
- MinGW-w64 (tested with v7.3.0, v8.1.0 and TDM-GCC v9.2.0)
- Microsoft Visual Studio (tested with Visual Studio Community 2019)
- LCOV for Windows [Optional, needed if tests and coverage are enabled using MinGW] (tested with v1.15.alpha1w)
- OpenCppCoverage [Optional, needed if tests and coverage are enabled using Visual Studio 2019] (tested with v0.9.8.0)
- A C/C++ compiler, either:
- On Linux:
OPTION | Description |
---|---|
-DCMAKE_BUILD_TYPE |
Selects build type (only for single-config generators) Debug Release (default)RelWithDebInfo (Release with debug info)MinSizeRel (Release with size optimization)Coverage (Debug with code coverage enabled) |
-DBUILD_SHARED_LIB |
Enables generation of shared libraryON (default)OFF |
-DBUILD_STATIC_LIB |
Enables generation of static libraryON (default)OFF |
-DENABLE_TEST |
Enables compilation and execution of testsON (default)OFF |
-DCPPUTEST_HOME |
Path to your CppUTest installation directory<filesystem path> |
-DLCOV_HOME |
Path to your LCOV installation directory<filesystem path> |
-DENABLE_INSTALLER |
Enables generation of installer packagesON (default)OFF |
-DBUILD_EXAMPLES |
Enables building examplesON (default)OFF |
-DCOVERAGE |
Enables code coverage in tests (only for multi-config generators) ON (default)OFF |
-DCOVERAGE_VERBOSE |
Enables verbose code coverageON OFF (default) |
-DCI_MODE |
Enables Continous Integration modeON OFF (default) |