命令后界面输出颜色
嵌入式终端界面输出日志时,为了区分输出的有用信息、错误信息,可以给不同级别的输出加上不同的颜色,以方便查看。
下面是颜色的定义:
//颜色宏定义
#define NONE " 33[m"
#define RED " 33[0;32;31m"
#define LIGHT_RED " 33[1;31m"
#define GREEN " 33[0;32;32m"
#define LIGHT_GREEN " 33[1;32m"
#define BLUE " 33[0;32;34m"
#define LIGHT_BLUE " 33[1;34m"
#define DARY_GRAY " 33[1;30m"
#define CYAN " 33[0;36m"
#define LIGHT_CYAN " 33[1;36m"
#define PURPLE " 33[0;35m"
#define LIGHT_PURPLE " 33[1;35m"
#define BROWN " 33[0;33m"
#define YELLOW " 33[1;33m"
#define LIGHT_GRAY " 33[0;37m"
#define WHITE " 33[1;37m"
使用方法
如下:
printf(YELLOW"this print msg is yellow!
"NONE);
这样打印出来的字符串: “this print msg is yellow!” 就是黄色的。
颜色值放在打印内容开始的双引号前面,结束时再双引号后面加上NONE,用于结束颜色作用域.
完成测试代码
#include <stdio.h>
//颜色宏定义
#define NONE " 33[m"
#define RED " 33[0;32;31m"
#define LIGHT_RED " 33[1;31m"
#define GREEN " 33[0;32;32m"
#define LIGHT_GREEN " 33[1;32m"
#define BLUE " 33[0;32;34m"
#define LIGHT_BLUE " 33[1;34m"
#define DARY_GRAY " 33[1;30m"
#define CYAN " 33[0;36m"
#define LIGHT_CYAN " 33[1;36m"
#define PURPLE " 33[0;35m"
#define LIGHT_PURPLE " 33[1;35m"
#define BROWN " 33[0;33m"
#define YELLOW " 33[1;33m"
#define LIGHT_GRAY " 33[0;37m"
#define WHITE " 33[1;37m"
int main()
{
printf(RED"红色****************************
"NONE);
printf(LIGHT_RED"亮红色**************************
"NONE);
printf(GREEN"绿色****************************
"NONE);
printf(LIGHT_GREEN"亮绿色****************************
"NONE);
printf(BLUE"蓝色******************************
"NONE);
printf(LIGHT_BLUE"亮蓝色****************************
"NONE);
printf(DARY_GRAY"灰色******************************
"NONE);
printf(CYAN"青色*****************************
"NONE);
printf(LIGHT_CYAN"亮青色****************************
"NONE);
printf(PURPLE"紫色*****************************
"NONE);
printf(LIGHT_PURPLE"亮紫色****************************
"NONE);
printf(BROWN"棕色*****************************
"NONE);
printf(YELLOW"黄色****************************
"NONE);
printf(LIGHT_GRAY"亮灰色*****************************
"NONE);
printf(WHITE"白色****************************
"NONE);
return 0;
}