crs.h - Installation & Usage
A lightweight, header-only C++ library for advanced console text styling using ANSI escape sequences.
Installation Guide
Part 1: Install CRS as a System Library (One-Time Setup)
These steps make the CRS library available for all your MinGW C++ projects.
# 1. Compile crs.cpp into an object file
g++ -c crs.cpp -o crs.o -std=c++17
# 2. Create the static library libcrs.a
ar rcs libcrs.a crs.o
# 3. Copy crs.h to MinGW's include directory
# (e.g., C:\msys64\mingw64\include\)
cp crs.h /mingw64/include/
# 4. Copy libcrs.a to MinGW's lib directory
# (e.g., C:\msys64\mingw64\lib\)
cp libcrs.a /mingw64/lib/Part 2: Use CRS in Your Projects
Now, when you want to start a new C++ project that uses CRS, follow these simple steps:
// Include crs.h in your C++ code
// Use angle brackets for headers installed in the system
#include <crs.h>
int main() {
crs::setTextColor("#00ff00");
crs::setBackgroundColor("#000000");
crs::setBold();
std::cout << "Bold green on black" << std::endl;
crs::unsetBold();
crs::resetColors();
return 0;
}When compiling, link the library using the -lcrs flag:
g++ your_main_file.cpp -o your_app -std=c++17 -lcrsNotes & Best Practices
- Ensure you are using an ANSI-compatible terminal for the styles to render correctly (e.g., Windows Terminal, macOS Terminal, Linux terminals).
- Always reset styles with
crs::resetColors()at the end of your program or before exiting a styled section to avoid "bleeding" styles into the rest of the console. - Avoid mixing
std::cerrandstd::coutwithout resetting styles, as they use different buffers and can lead to unexpected formatting. - The
printGradientText(...)function is deprecated and no longer functional.
Created by Dominik [VEX7] · Inspired by standard UNIX and ANSI escape codes.
If you enjoy using crs.h, give it a ⭐ on GitHub!