-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorPrint.h
141 lines (133 loc) · 5.73 KB
/
ColorPrint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* ColorPrint
*
* It is very small but useful, easy to use c++ to create colorful code
*
*/
#pragma once
#include <iostream>
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
enum ConsoleColor {
C_RED = FOREGROUND_INTENSITY | FOREGROUND_RED,
C_GREEN = FOREGROUND_INTENSITY | FOREGROUND_GREEN,
C_BLUE = FOREGROUND_INTENSITY | FOREGROUND_BLUE,
C_YELLOW = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN,
C_CYAN = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE,
C_WHITE = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
C_BLACK = 0,
};
static HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
#define CC_RED SetConsoleTextAttribute(handle,C_RED|C_BLACK)
#define CC_GREEN SetConsoleTextAttribute(handle,C_GREEN|C_BLACK)
#define CC_BLUE SetConsoleTextAttribute(handle,C_BLUE|C_BLACK)
#define CC_YELLOW SetConsoleTextAttribute(handle,C_YELLOW|C_BLACK)
#define CC_CYAN SetConsoleTextAttribute(handle,C_CYAN|C_BLACK)
#define CC_BLACK SetConsoleTextAttribute(handle,C_BLACK|C_BLACK)
#define CC_WHITE SetConsoleTextAttribute(handle,C_WHITE|C_BLACK)
#define CC_RESET SetConsoleTextAttribute(handle,C_WHITE|C_BLACK)
#ifndef NoMessage
#define PRINT(level,content) do{\
switch (level) {\
/* For Success */\
case 'S': CC_GREEN; std::cout << "[SUCCESS " << __FUNCTION__ << ":" << __LINE__ << "] " << content << std::endl; CC_RESET; break;\
/* For Notice */\
case 'N': CC_CYAN; std::cout << "[NOTICE " << __FUNCTION__ << ":" << __LINE__ << "] " << content << std::endl; CC_RESET; break;\
/* For Warn */\
case 'W': CC_YELLOW; std::cout << "[WARNNING " << __FUNCTION__ << ":" << __LINE__ << "] " << content << std::endl; CC_RESET; break;\
/* For Error */\
case 'E': CC_RED; std::cout << "[ERROR " << __FUNCTION__ << ":" << __LINE__ << "] " << content << std::endl; CC_RESET; break;\
/* For Normal Info */\
case 'I': std::cout << "[INFO " << __FUNCTION__ << ":" << __LINE__ << "] " << content << std::endl; break;\
default : break;\
}\
}while(0)
#define PRINTF(level,format,...) do{\
switch (level) {\
/* For Success */\
case 'S': CC_GREEN; printf("[SUCCESS %s:%d] " format "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); CC_RESET; break; \
/* For Notice */\
case 'N': CC_CYAN; printf("[NOTICE %s:%d] " format "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); CC_RESET; break; \
/* For Warn */\
case 'W': CC_YELLOW; printf("[WARNNING %s:%d] " format "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); CC_RESET; break; \
/* For Error */\
case 'E': CC_RED; printf("[ERROR %s:%d] " format "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); CC_RESET; break; \
/* For Normal Info */\
case 'I': printf("[INFO %s:%d] " format "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); CC_RESET; break; \
default: break; \
}\
}while (0)
#else
#define PRINT(level,content) do{\
switch (level) {\
/* For Error */\
case 'E': CC_RED; std::cout << "[ERROR " << __FUNCTION__ << ":" << __LINE__ << "] " << content << std::endl; CC_RESET; break;\
default : break;\
}\
}while(0)
#define PRINTF(level,format,...) do{\
switch (level) {\
/* For Error */\
case 'E': CC_RED; printf("[ERROR %s:%d] " format "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); CC_RESET; break; \
default : break;\
}\
}while(0)
#endif
#else
#define CC_RED "\033[31m"
#define CC_GREEN "\033[32m"
#define CC_BLUE "\033[34m"
#define CC_YELLOW "\033[33m"
#define CC_CYAN "\033[36m"
#define CC_WHITE "\033[37m"
#define CC_BLACK "\033[30m"
#define CC_RESET "\033[0m"
#ifndef NoMessage
#define PRINT(level,content) do{\
switch (level) {\
/* For Success */\
case 'S': std::cout << CC_GREEN << "[SUCCESS " << __FUNCTION__ << ":" << __LINE__ << "] " << content << CC_RESET << std::endl; break;\
/* For Notice */\
case 'N': std::cout << CC_CYAN << "[NOTICE " << __FUNCTION__ << ":" << __LINE__ << "] " << content << CC_RESET << std::endl; break;\
/* For Warn */\
case 'W': std::cout << CC_YELLOW << "[WARNNING " << __FUNCTION__ << ":" << __LINE__ << "] " << content << CC_RESET << std::endl; break;\
/* For Error */\
case 'E': std::cout << CC_RED << "[ERROR " << __FUNCTION__ << ":" << __LINE__ << "] " << content << CC_RESET << std::endl; break;\
/* For Normal Info */\
case 'I': std::cout << "[INFO " << __FUNCTION__ << ":" << __LINE__ << "] " << content << std::endl; break;\
default : break;\
}\
}while(0)
#define PRINTF(level,format,...) do{\
switch (level) {\
/* For Success */\
case 'S': printf(CC_GREEN "[SUCCESS %s:%d] " format CC_RESET "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); break; \
/* For Notice */\
case 'N': printf(CC_CYAN "[NOTICE %s:%d] " format CC_RESET "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); break; \
/* For Warn */\
case 'W': printf(CC_YELLOW "[WARNNING %s:%d] " format CC_RESET "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); break; \
/* For Error */\
case 'E': printf(CC_RED "[ERROR %s:%d] " format CC_RESET "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); break; \
/* For Normal Info */\
case 'I': printf("[INFO %s:%d] " format CC_RESET "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); break; \
default: break; \
}\
}while (0)
#else
#define PRINT(level,content) do{\
switch (level) {\
/* For Error */\
case 'E': std::cout << CC_RED << "[ERROR " << __FUNCTION__ << ":" << __LINE__ << "] " << content << CC_RESET << std::endl; break;\
default : break;\
}\
}while(0)
#define PRINTF(level,format,...) do{\
switch (level) {\
/* For Error */\
case 'E': printf(CC_RED "[ERROR %s:%d] " format CC_RESET "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); break; \
default: break; \
}\
}while (0)
#endif
#endif // _WIN32