printf颜色
格式
printf("\033[?m%s\033[0m", str);
多个属性以;分隔
属性:
\033[0m:关闭所有属性
\033[1m:设置高亮度
\033[4m:下划线
\033[5m:闪烁
\033[7m:反显
\033[8m:消隐
\033[30m ~ \033[37m:设置字体颜色
\033[40m ~ \033[47m:设置字背景颜色
\033[nA:光标上移n行
\033[nB:光标下移n行
\033[nC:光标右移n行
\033[nD:光标左移n行
字背景颜色:
40: 黑
41: 红
42: 绿
43: 黄
44: 蓝
45: 紫
46: 深绿
47: 白色
字体颜色:
30: 黑
31: 红
32: 绿
33: 黄
34: 蓝
35: 紫
36: 深绿
37: 白色
举例
printf("\033[42;31;4m%s\033[0m\n", "hello");
可直接使用的代码
#define NONE "\033[m"
#define RED "\033[0;32;31m"
#define LIGHT_RED "\033[1;31m"
#define GREEN "\033[0;32;32m"
#define LIGHT_GREEN "\033[1;32m"
#define BLUE "\033[0;32;34m"
#define LIGHT_BLUE "\033[1;34m"
#define DARY_GRAY "\033[1;30m"
#define CYAN "\033[0;36m"
#define LIGHT_CYAN "\033[1;36m"
#define PURPLE "\033[0;35m"
#define LIGHT_PURPLE "\033[1;35m"
#define BROWN "\033[0;33m"
#define YELLOW "\033[1;33m"
#define LIGHT_GRAY "\033[0;37m"
#define WHITE "\033[1;37m"
#define GreenLog(fomat,args...) do{printf(LIGHT_GREEN);printf(fomat,##args);printf(NONE);}while(0)
#define RedLog(fomat,args...) do{printf(LIGHT_RED);printf(fomat,##args);printf(NONE);}while(0)
#define BlueLog(fomat,args...) do{printf(LIGHT_BLUE);printf(fomat,##args);printf(NONE);}while(0)
#define YellowLog(fomat,args...) do{printf(YELLOW);printf(fomat,##args);printf(NONE);}while(0)
#define BrownLog(fomat,args...) do{printf(BROWN);printf(fomat,##args);printf(NONE);}while(0)
#define CyanLog(fomat,args...) do{printf(LIGHT_CYAN);printf(fomat,##args);printf(NONE);}while(0)
#define GrayLog(fomat,args...) do{printf(DARY_GRAY);printf(fomat,##args);printf(NONE);}while(0)
#define LightPurpleLog(fomat,args...) do{printf(LIGHT_PURPLE);printf(fomat,##args);printf(NONE);}while(0)