I'm using ANSI color codes to format my output in an Unix console.
const auto& getCode(Color mColor)
{
static std::map<Color, std::string> codes;
// ...
return codes[mColor]
}
cout << getCode(Color::Red) << "red text";
When using manipulators such as std::setw
or std::left
, however, the results are affected by the color code, as it is a bunch of characters.
How should I deal with this issue? Is there a way to make stream manipulators ignore color codes?