https://github.com/lecrapouille/terminalcolor
[Lib][Functional][Stable] A minimal C++11 header-only file for adding colors to your std::cout functions
https://github.com/lecrapouille/terminalcolor
color cpp terminal
Last synced: 2 months ago
JSON representation
[Lib][Functional][Stable] A minimal C++11 header-only file for adding colors to your std::cout functions
- Host: GitHub
- URL: https://github.com/lecrapouille/terminalcolor
- Owner: Lecrapouille
- License: unlicense
- Created: 2020-05-04T21:50:53.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-08T19:25:17.000Z (about 6 years ago)
- Last Synced: 2025-04-07T22:34:35.157Z (about 1 year ago)
- Topics: color, cpp, terminal
- Language: C++
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TerminalColor
A single C++11 header-only file for adding colors to your std::cout function.
This project has been inspired by https://github.com/agauniyal/rang and https://github.com/agauniyal/rang/issues/103
## Example
```
#define WARNING_COLOR termcolor::color(termcolor::style::bold, termcolor::fg::red)
#define ERROR_COLOR termcolor::color(termcolor::style::bold, termcolor::fg::green)
#define DEFAULT_COLOR termcolor::color()
termcolor::enable();
std::cout << WARNING_COLOR << "- Warning\n"
<< ERROR_COLOR << "+ Error"
<< DEFAULT_COLOR << std::endl;
termcolor::disable();
std::cout << WARNING_COLOR << "- Warning\n"
<< ERROR_COLOR << "+ Error"
<< DEFAULT_COLOR << std::endl;
```
Will produce something like this in your console:
```diff
- Warning
+ Error
```
```
- Warning
+ Error
```
If you want to ignore color requests call `termcolor::disable();` To enable color back: `termcolor::enable();`. For more examples see the [unit-test file](tests/TerminalColorTests.cpp).
## Project using this library
https://github.com/Lecrapouille/SimForth
