看别人的开源项目的时候发现,原来在终端可以打印带颜色的字符串的。。还蛮有意思的,只需要在待打印的字符串前面和后面分别加一串修饰字符就行了。
下面是C语言的一个例子:
#include <stdio.h>
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_YELLOW "\x1b[33m"
#define ANSI_COLOR_BLUE "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"
int main() {
printf(ANSI_COLOR_RED "This text is RED!"