C语言(彩色打印)
1.相关链接
2.代码如下:
#ifndef __DEBUG_H__
#define __DEBUG_H__
#include <stdio.h>
#include <stdbool.h>
#define ENABLE true
#define DISABLE false
#define DEBUG_TEST ENABLE
/*
* Color print format : \033[字背景颜色;字体颜色m
* or: \e[字背景颜色;字体颜色m
*the color num range of font background : 40 ~ 49
40:黑
41:深红
42:绿
43:黄色
44:蓝色
45:紫色
46:深绿
47:白色
48:
49:
*
* the color num range of font : 30 ~ 39
30:黑
31:红
32:绿
33:黄
34:蓝色
35:紫色
36:深绿
37:白色
38:
39:
*ANSI control code infomation
\e[0m : 关闭所有属性
\e[1m : 设置高亮度
\e[4m : 下划线
\e[5m : 闪烁
\e[7m :反显
\e[8m :消隐
*/
#define NONE "\e[m"
#define RED "\e[0;31m"
#define GREEN "\e[0;32m"
#define YELLOW "\e[0;33m"
#define BLUE "\e[0;34m"
#define DEBUG_MSG(string...) \
if (DEBUG_TEST)\
{\
printf("FILE :"BLUE"%s"NONE", FUNC :"GREEN"%s"NONE", LINE :"RED"%d"NONE" --> "\
,__FILE__, __func__, __LINE__);\
printf(string);\
}
#define DEBUG_WRNMSG(string...) \
if (DEBUG_TEST)\
{\
printf("FILE :"BLUE"%s"NONE", FUNC :"GREEN"%s"NONE", LINE :"RED"%d"NONE" --> "\
,__FILE__, __func__, __LINE__);\
printf(YELLOW""string""NONE);\
}
#define DEBUG_ERRMSG(string...) \
if (DEBUG_TEST)\
{\
printf("FILE :"BLUE"%s"NONE", FUNC :"GREEN"%s"NONE", LINE :"RED"%d"NONE" --> "\
,__FILE__, __func__, __LINE__);\
printf(RED""string""NONE);\
}
#endif