- Timestamp:
- Dec 2, 2013, 9:25:38 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/PacpusLib/ColorSeverityFormatter.hpp
r240 r242 88 88 } 89 89 90 template < typename CharT >91 struct ColorFormatter92 {93 ColorFormatter()94 : mStreamHandle(GetStdHandle(STD_OUTPUT_HANDLE))95 {96 }97 98 void operator()(boost::log::basic_formatting_ostream<CharT>& strm, SeverityLevel const& sev)99 {100 // Gets the current text color.101 CONSOLE_SCREEN_BUFFER_INFO bufferInfo;102 GetConsoleScreenBufferInfo(mStreamHandle, &bufferInfo);103 mSavedConsoleBufferInfo = bufferInfo.wAttributes;104 105 // We need to flush the stream buffers into the console before each106 // SetConsoleTextAttribute call lest it affect the text that is already107 // printed but has not yet reached the console.108 fflush(stdout);109 SetConsoleTextAttribute(mStreamHandle, getColorAttribute(getColor(sev)) | FOREGROUND_INTENSITY);110 }111 112 const HANDLE mStreamHandle;113 WORD mSavedConsoleBufferInfo;114 };115 116 template < typename CharT >117 struct DefaultFormatter118 {119 DefaultFormatter() //(WORD savedConsoleBufferInfo)120 : mStreamHandle(GetStdHandle(STD_OUTPUT_HANDLE))121 //, mSavedConsoleBufferInfo(savedConsoleBufferInfo)122 , mSavedConsoleBufferInfo(getColorAttribute(COLOR_WHITE) | FOREGROUND_INTENSITY) // FIXME: restore old value, not just reset123 {124 }125 126 void operator()(boost::log::basic_formatting_ostream<CharT>& strm, SeverityLevel const& /*sev*/)127 {128 fflush(stdout);129 // Restores the text color.130 SetConsoleTextAttribute(mStreamHandle, mSavedConsoleBufferInfo);131 }132 133 const HANDLE mStreamHandle;134 WORD mSavedConsoleBufferInfo;135 };136 137 90 #else 138 91 … … 175 128 } 176 129 130 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 131 177 132 template < typename CharT > 178 133 struct ColorFormatter 179 134 { 135 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 136 ColorFormatter() 137 : mStreamHandle(GetStdHandle(STD_OUTPUT_HANDLE)) 138 { 139 } 140 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 141 180 142 void operator()(boost::log::basic_formatting_ostream<CharT>& strm, SeverityLevel const& sev) 181 143 { 144 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 145 // Gets the current text color. 146 CONSOLE_SCREEN_BUFFER_INFO bufferInfo; 147 GetConsoleScreenBufferInfo(mStreamHandle, &bufferInfo); 148 mSavedConsoleBufferInfo = bufferInfo.wAttributes; 149 150 // We need to flush the stream buffers into the console before each 151 // SetConsoleTextAttribute call lest it affect the text that is already 152 // printed but has not yet reached the console. 153 fflush(stdout); 154 SetConsoleTextAttribute(mStreamHandle, getColorAttribute(getColor(sev)) | FOREGROUND_INTENSITY); 155 #else 182 156 strm << getAnsiColorCode(getColor(sev)).c_str(); 183 } 184 }; 157 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 158 } 159 160 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 161 const HANDLE mStreamHandle; 162 WORD mSavedConsoleBufferInfo; 163 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 164 }; 165 185 166 template < typename CharT > 186 167 struct DefaultFormatter 187 168 { 169 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 170 DefaultFormatter() //(WORD savedConsoleBufferInfo) 171 : mStreamHandle(GetStdHandle(STD_OUTPUT_HANDLE)) 172 //, mSavedConsoleBufferInfo(savedConsoleBufferInfo) 173 , mSavedConsoleBufferInfo(getColorAttribute(COLOR_WHITE) | FOREGROUND_INTENSITY) // FIXME: restore old value, not just reset 174 { 175 } 176 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 177 188 178 void operator()(boost::log::basic_formatting_ostream<CharT>& strm, SeverityLevel const& /*sev*/) 189 179 { 180 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 181 fflush(stdout); 182 // Restores the text color. 183 SetConsoleTextAttribute(mStreamHandle, mSavedConsoleBufferInfo); 184 #else 190 185 strm << getAnsiColorCodeRestoreDefault().c_str(); 191 } 192 }; 193 194 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 186 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 187 } 188 189 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 190 const HANDLE mStreamHandle; 191 WORD mSavedConsoleBufferInfo; 192 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE) 193 }; 195 194 196 195 template< typename T, typename FallbackPolicyT, typename CharT >
Note:
See TracChangeset
for help on using the changeset viewer.