1.彩色打印调试
1 /******************************************************************* 2 * > File Name: 00-test.c 3 * > Author: fly 4 * > Mail: XXXXXXXX@icode.com 5 * > Create Time: Sun 15 Oct 2017 11:46:46 AM CST 6 ******************************************************************/ 7 8 #include <stdio.h> 9 10 /*-----------------------------------color------------------------ 11 *Format:\033[attribute;backgroudColor;fontColor 12 * 30~39: set the color of font; 40~49:set the color of backgroud; 13 * 0:close all attributes; 14 * 1:set the attributes:light and wide font; 15 * 4:line 16 * 5:flicker 17 * 7:reverse display 18 * 8:blanking 19 * */ 20 #define NONE "\033[m" //复原 21 #define RED "\033[0;31m" //红色 22 #define LIGHT_RED "\033[1;31m" 23 #define LIGHT_RED1 "\033[1;42;31m" 24 #define LIGHT_RED2 "\033[1;43;31m" 25 #define LIGHT_RED3 "\033[1;44;31m" 26 #define LIGHT_RED4 "\033[1;47;31m" 27 #define LIGHT_RED5 "\033[7;47;31m" 28 #define LIGHT_RED6 "\033[5;47;31m" 29 #define GREEN "\033[0;32m" 30 #define LIGHT_GREEN "\e[1;32m" 31 #define BLUE "\033[0;34m" 32 #define LIGHT_BLUE "\033[1;34;24m" 33 #define DARY_GRAY "\033[1;30m" //深灰 34 #define GYAN "\033[0;36m" //蓝绿色 35 #define LIGHT_CYAN "\033[1;36m" 36 #define PURPLE "\033[0;35m" 37 #define LIGHT_PURPLE "\033[1;35m" 38 #define BROWN "\033[0;33m" 39 #define YELLOW "\033[1;33m" 40 #define LIGHT_GRAY "\033[0;37m" //高亮灰 41 #define WHITE "\033[1;37m" //白色 42 43 typedef enum{ 44 COLOR_NONE, 45 COLOR_RED, 46 COLOR_LIGHT_RED, 47 COLOR_LIGHT_RED1, 48 COLOR_LIGHT_RED2, 49 COLOR_LIGHT_RED3, 50 COLOR_LIGHT_RED4, 51 COLOR_LIGHT_RED5, 52 COLOR_LIGHT_RED6, 53 COLOR_GREEN, 54 COLOR_LIGHT_GREEN, 55 COLOR_BLUE, 56 COLOR_LIGHT_BLUE, 57 COLOR_DARY_GRAY, 58 COLOR_GYAN, 59 COLOR_LIGHT_CYAN, 60 COLOR_PURPLE, 61 COLOR_LIGHT_PURPLE, 62 COLOR_BROWN, 63 COLOR_YELLOW, 64 COLOR_LIGHT_GRAY, 65 COLOR_WHITE, 66 COLOR_MAX 67 }debug_color; 68 69 char *debug_color_str[COLOR_MAX]={ 70 "\e[m", 71 "\e[0;31m", 72 "\e[1;31m", 73 "\e[1;42;31m", 74 "\e[1;43;31m", 75 "\e[1;44;31m", 76 "\e[1;47;31m", 77 "\e[7;47;31m", 78 "\e[5;47;31m", 79 "\e[0;32m", 80 "\e[1;32m", 81 "\e[0;34m", 82 "\e[1;34;24m", 83 "\e[1;30m", 84 "\e[0;36m", 85 "\e[1;36m", 86 "\e[0;35m", 87 "\e[1;35m", 88 "\e[0;33m", 89 "\e[1;33m", 90 "\e[0;37m", 91 "\e[1;37m", 92 }; 93 94 int main(int argc, char* argv[]) 95 { 96 puts(RED"RED"NONE); 97 puts(LIGHT_RED"LIGHT_RED"NONE); 98 puts(LIGHT_RED1"LIGHT_RED1"NONE); 99 puts(LIGHT_RED2"LIGHT_RED2"NONE); 100 puts(LIGHT_RED3"LIGHT_RED3"NONE); 101 puts(LIGHT_RED4"LIGHT_RED4"NONE); 102 puts(LIGHT_RED5"LIGHT_RED5"NONE); 103 puts(LIGHT_RED6"LIGHT_RED6"NONE); 104 puts(GREEN"GREEN"NONE); 105 puts(LIGHT_GREEN"LIGHT_GREEN"NONE); 106 puts(BLUE"BLUE"NONE); 107 puts(LIGHT_BLUE"LIGHT_BLUE"NONE); 108 puts(DARY_GRAY"DARY_GRAY"NONE); 109 puts(GYAN"GYAN"NONE); 110 puts(LIGHT_CYAN"LIGHT_CYAN"NONE); 111 puts(PURPLE"PURPLE"NONE); 112 puts(LIGHT_PURPLE"LIGHT_PURPLE"NONE); 113 puts(BROWN"BROWN"NONE); 114 puts(YELLOW"YELLOW"NONE); 115 puts(LIGHT_GRAY"LIGHT_GRAY"NONE); 116 puts(WHITE"WHITE"NONE); 117 118 puts("Output color_debug:"); 119 int i; 120 for(i = 0; i< COLOR_MAX; i++){ 121 printf("%s\n", debug_color_str[i]); 122 } 123 124 puts(LIGHT_RED4"This is a test !"NONE); 125 126 printf("File :%s, Func :%s, Line :%d\n", __FILE__, __func__, __LINE__); 127 128 return 0; 129 }