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
|
#ifndef NPP_SYS_CONSOLE_HPP
#define NPP_SYS_CONSOLE_HPP
#include <iostream>
#if WIN32
#include <windows.h>
#else
#include <sstream>
#endif
namespace con {
/**
* @brief Représente une manipulateur de console.
*/
template <unsigned int color, bool bold, bool blink, bool reset>
class con_manipulator
{
public:
/**
* @brief Construit un nouveau manipulateur de console.
*/
con_manipulator() { }
/**
* @brief Permet de modifier les attributs de la console std::cout.
* @param[in] o La console à modifier (std::cout).
* @param[in] c La couleur à mettre.
* @return Le flux modifié (std::cout).
*/
friend std::ostream& operator<<(std::ostream& o, const con_manipulator<color, bold, blink, reset>& c)
{
#if WIN32
HANDLE hout = ::GetStdHandle(STD_OUTPUT_HANDLE);
unsigned int col = color;
if(bold)
{
if(col & (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)) col |= FOREGROUND_INTENSITY;
if(col & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED)) col |= BACKGROUND_INTENSITY;
}
::SetConsoleTextAttribute(hout, col);
#else
std::stringstream ss;
ss << "\033[" << (bold ? "1" : "0") << ";" << color << "m";
o << ss.str();
#endif
return o;
}
};
#if WIN32
typedef con_manipulator<0, false, false, false> black;
typedef con_manipulator<FOREGROUND_BLUE, false, false, false> darkblue;
typedef con_manipulator<FOREGROUND_GREEN, false, false, false> darkgreen;
typedef con_manipulator<FOREGROUND_BLUE | FOREGROUND_GREEN, false, false, false> darkcyan;
typedef con_manipulator<FOREGROUND_RED, false, false, false> darkred;
typedef con_manipulator<FOREGROUND_BLUE | FOREGROUND_RED, false, false, false> darkmagenta;
typedef con_manipulator<FOREGROUND_GREEN | FOREGROUND_RED, false, false, false> darkyellow;
typedef con_manipulator<FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED, false, false, false> gray;
typedef con_manipulator<0, true, false, false> darkgray;
typedef con_manipulator<FOREGROUND_BLUE, true, false, false> blue;
typedef con_manipulator<FOREGROUND_GREEN, true, false, false> green;
typedef con_manipulator<FOREGROUND_BLUE | FOREGROUND_GREEN, true, false, false> cyan;
typedef con_manipulator<FOREGROUND_RED, true, false, false> red;
typedef con_manipulator<FOREGROUND_BLUE | FOREGROUND_RED, true, false, false> magenta;
typedef con_manipulator<FOREGROUND_GREEN | FOREGROUND_RED, true, false, false> yellow;
typedef con_manipulator<FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED, true, false, false> white;
typedef con_manipulator<0, false, false, false> bg_black;
typedef con_manipulator<BACKGROUND_BLUE, false, false, false> bg_darkblue;
typedef con_manipulator<BACKGROUND_GREEN, false, false, false> bg_darkgreen;
typedef con_manipulator<BACKGROUND_BLUE | BACKGROUND_GREEN, false, false, false> bg_darkcyan;
typedef con_manipulator<BACKGROUND_RED, false, false, false> bg_darkred;
typedef con_manipulator<BACKGROUND_BLUE | BACKGROUND_RED, false, false, false> bg_darkmagenta;
typedef con_manipulator<BACKGROUND_GREEN | BACKGROUND_RED, false, false, false> bg_darkyellow;
typedef con_manipulator<BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED, false, false, false> bg_gray;
typedef con_manipulator<0, true, false, false> bg_darkgray;
typedef con_manipulator<BACKGROUND_BLUE, true, false, false> bg_blue;
typedef con_manipulator<BACKGROUND_GREEN, true, false, false> bg_green;
typedef con_manipulator<BACKGROUND_BLUE | BACKGROUND_GREEN, true, false, false> bg_cyan;
typedef con_manipulator<BACKGROUND_RED, true, false, false> bg_red;
typedef con_manipulator<BACKGROUND_BLUE | BACKGROUND_RED, true, false, false> bg_magenta;
typedef con_manipulator<BACKGROUND_GREEN | BACKGROUND_RED, true, false, false> bg_yellow;
typedef con_manipulator<BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED, true, false, false> bg_white;
#else
typedef con_manipulator<30, false, false, false> black;
typedef con_manipulator<31, false, false, false> darkred;
typedef con_manipulator<32, false, false, false> darkgreen;
typedef con_manipulator<33, false, false, false> darkyellow;
typedef con_manipulator<34, false, false, false> darkblue;
typedef con_manipulator<35, false, false, false> darkmagenta;
typedef con_manipulator<36, false, false, false> darkcyan;
typedef con_manipulator<37, false, false, false> gray;
typedef con_manipulator<30, true, false, false> darkgray;
typedef con_manipulator<31, true, false, false> red;
typedef con_manipulator<32, true, false, false> green;
typedef con_manipulator<33, true, false, false> yellow;
typedef con_manipulator<34, true, false, false> blue;
typedef con_manipulator<35, true, false, false> magenta;
typedef con_manipulator<36, true, false, false> cyan;
typedef con_manipulator<37, true, false, false> white;
typedef con_manipulator<40, false, false, false> bg_black;
typedef con_manipulator<41, false, false, false> bg_darkred;
typedef con_manipulator<42, false, false, false> bg_darkgreen;
typedef con_manipulator<43, false, false, false> bg_darkyellow;
typedef con_manipulator<44, false, false, false> bg_darkblue;
typedef con_manipulator<45, false, false, false> bg_darkmagenta;
typedef con_manipulator<46, false, false, false> bg_darkcyan;
typedef con_manipulator<47, false, false, false> bg_gray;
typedef con_manipulator<40, true, false, false> bg_darkgray;
typedef con_manipulator<41, true, false, false> bg_red;
typedef con_manipulator<42, true, false, false> bg_green;
typedef con_manipulator<43, true, false, false> bg_yellow;
typedef con_manipulator<44, true, false, false> bg_blue;
typedef con_manipulator<45, true, false, false> bg_magenta;
typedef con_manipulator<46, true, false, false> bg_cyan;
typedef con_manipulator<47, true, false, false> bg_white;
#endif
}
#endif // NPP_SYS_CONSOLE_HPP |
Partager