1 year ago
#374449
BadUsernameIdea
How to do bold text using the ISO standard escape sequences?
I've created a namespace which would store ANSI values for logging purposes.
namespace ANSI {
static const char *BLACK_BG = "\x1B[48;2;0;0;0m";
static const char *RED = "\x1B[38;2;255;0;0m";
static const char *GREEN = "\x1B[38;2;0;255;0m";
static const char *GREY = "\x1B[38;2;70;70;70m";
static const char *EXIT = "\x1B[0m";
static std::ostream &BOLD(std::ostream& log) { return log << "\e[1m"; }
}
// Example usage:
// std::cout << ANSI::BOLD << ANSI::GREEN << "This is bold green text" << ANSI::EXIT << "\n";
But when I try to compile using the -pedantic
flag, it tells me that \e[1m
is not an ISO standard escape sequence. It doesn't show the error if I remove the flag but I want to keep it at the same time.
P.S. If I'm doing something wrong with the code above, please let me know.
EDIT:
The bold escape sequence \033[1m
works for my code.
c++
escaping
ansi-escape
0 Answers
Your Answer