如何使用 ISO 标准转义序列制作粗体文本?
我创建了一个命名空间,用于存储 ANSI 值以用于日志记录。
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";
但是当我尝试使用 -pedantic
标志进行编译时,它告诉我 \e[1m
不是 ISO 标准转义序列。如果我删除该标志,它不会显示错误,但我想同时保留它。
PS 如果我上面的代码做错了什么,请告诉我。
编辑: 粗体转义序列 \033[1m
适用于我的代码。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论