There's a funny thing still, aside from what kbw mentioned. One important aspect of programming is the notion of the "interface" of the functionality, and its separation from the actual implementation of the functionality.
The goal here is that you want the user to be able to use your ConsoleColor class to easily produce colored text. Sure, that's good. The issue is that with lines like "\x1b[0;0m" you're forcing the user to still know how to implement ConsoleColor themselves (i.e. they have to know that it's some specific set of magic strings they need to invoke for console to
stop being a particular color).
One easy way to do this would be to just have a "ConsoleColor::Reset" static variable that the user also invokes, so they needn't worry about what "\x1b[0;0m" means.
e.g.
cout << ConsoleColor::Red << "This is red " << ConsoleColor::Reset << "This is normal\n";
Another way to do this would for a ConsoleColor to always handle resetting the console itself. This is a less straight-forward path, but might be better depending on the intended use-case.
For example, you could have something like:
1 2 3 4 5
|
ConsoleColor(std::cout, ConsoleColor::Red) << "This is red text";
// or maybe
ConsoleColor(std::cout) << ConsoleColor::Red << "This is red text";
std::cout << "This is normal text.";
| |
where the destruction of the ConsoleColor object automatically resets the color state of the stream by sending "\x1b[0;0m" to it.
What I showed might still be a bit clunky, but it's just to get the idea across of possible alternatives.