MCPcopy Create free account
hub / github.com/GameTechDev/PresentMon / PrintColor

Function PrintColor

PresentMon/Console.cpp:309–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307}
308
309static int PrintColor(WORD color, wchar_t const* format, va_list val)
310{
311 #ifndef NDEBUG
312 {
313 wchar_t buffer[64];
314 VPrint(buffer, _countof(buffer), format, val);
315 OutputDebugStringW(buffer);
316 }
317 #endif
318
319 wchar_t* pformat = (wchar_t*) format;
320
321 HANDLE console = GetStdHandle(STD_ERROR_HANDLE);
322 CONSOLE_SCREEN_BUFFER_INFO info = {};
323 auto setColor = console != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(console, &info) != 0;
324 if (setColor) {
325 auto bg = info.wAttributes & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
326 if (bg == 0) {
327 color |= FOREGROUND_INTENSITY;
328 }
329 SetConsoleTextAttribute(console, WORD(bg | color));
330
331 auto formatLen = wcslen(format);
332 if (formatLen > 0 && format[formatLen - 1] == L'\n') {
333 auto size = sizeof(wchar_t) * formatLen;
334 pformat = (wchar_t*) malloc(size);
335 memcpy(pformat, format, size);
336 pformat[formatLen - 1] = '\0';
337 }
338 }
339
340 int c = vfwprintf(stderr, pformat, val);
341
342 if (setColor) {
343 SetConsoleTextAttribute(console, info.wAttributes);
344
345 if (pformat != format) {
346 c += fwprintf(stderr, L"\n");
347 free(pformat);
348 }
349 }
350
351 return c;
352}
353
354int PrintWarning(wchar_t const* format, ...)
355{

Callers 2

PrintWarningFunction · 0.85
PrintErrorFunction · 0.85

Calls 1

VPrintFunction · 0.85

Tested by

no test coverage detected