44#include < string>
55#include < iostream>
66
7+ #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
8+ #include < windows.h>
9+ #endif
10+
711template <typename T>
812constexpr void printInfo (T& msg){
913 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
14+ HANDLE hConsole;
15+ hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
16+ SetConsoleTextAttribute (hConsole, 2 );
1017 std::cout << msg;
18+ SetConsoleTextAttribute (hConsole, 7 );
1119 #else
1220 std::cout << " \033 [1;32m" << msg << " \033 [0m" ;
1321 #endif
1422}
1523
24+ template <typename T, typename ... arguments>
25+ constexpr void printInfo (T& msg, arguments... args) {
26+ #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
27+ HANDLE hConsole;
28+ hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
29+ SetConsoleTextAttribute (hConsole, 2 );
30+ std::cout << msg;
31+ SetConsoleTextAttribute (hConsole, 7 );
32+ #else
33+ std::cout << " \033 [1;32m" << msg;
34+ #endif
35+ printInfo (args...);
36+ }
37+
38+
1639template <typename T>
1740constexpr void printWarning (T& msg){
1841 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
19- std::cout << msg;
42+ HANDLE hConsole;
43+ hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
44+ SetConsoleTextAttribute (hConsole, 14 );
45+ std::cout << msg;
46+ SetConsoleTextAttribute (hConsole, 7 );
2047 #else
2148 std::cout << " \033 [1;33m" << msg << " \033 [0m" ;
2249 #endif
@@ -25,27 +52,26 @@ constexpr void printWarning(T& msg){
2552template <typename T, typename ... arguments>
2653constexpr void printWarning (T& msg, arguments... args){
2754 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
28- std::cout<< msg;
55+ HANDLE hConsole;
56+ hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
57+ SetConsoleTextAttribute (hConsole, 14 );
58+ std::cout << msg;
59+ SetConsoleTextAttribute (hConsole, 7 );
2960 #else
3061 std::cout << " \033 [1;33m" << msg;
3162 #endif
3263 printWarning (args...);
3364}
3465
35- template <typename T, typename ... arguments>
36- constexpr void printInfo (T& msg, arguments... args){
37- #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
38- std::cout<< msg;
39- #else
40- std::cout << " \033 [1;32m" << msg;
41- #endif
42- printInfo (args...);
43- }
4466
4567template <typename T>
4668constexpr void printError (T& msg){
4769 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
48- std::cout << msg;
70+ HANDLE hConsole;
71+ hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
72+ SetConsoleTextAttribute (hConsole, 4 );
73+ std::cout << msg;
74+ SetConsoleTextAttribute (hConsole, 7 );
4975 #else
5076 std::cout << msg << " \033 [0m" ;
5177 #endif
@@ -56,7 +82,11 @@ constexpr void printError(T& msg){
5682template <typename T, typename ... arguments>
5783constexpr void printError (T& msg, arguments... args){
5884 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
59- std::cout<< msg;
85+ HANDLE hConsole;
86+ hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
87+ SetConsoleTextAttribute (hConsole, 4 );
88+ std::cout << msg;
89+ SetConsoleTextAttribute (hConsole, 7 );
6090 #else
6191 std::cout << " \033 [1;31m" << msg;
6292 #endif
0 commit comments