Skip to content

Commit 4366ff9

Browse files
DannyDaemonicYellowRoseCx
authored andcommitted
Handle ENABLE_VIRTUAL_TERMINAL_PROCESSING more gracefully on earlier versions of Windows.
1 parent 811ff85 commit 4366ff9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

examples/console.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <windows.h>
1111
#include <fcntl.h>
1212
#include <io.h>
13+
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
14+
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
15+
#endif
1316
#else
1417
#include <climits>
1518
#include <sys/ioctl.h>
@@ -68,9 +71,10 @@ namespace console {
6871
}
6972
}
7073
if (hConsole) {
71-
// Enable ANSI colors on Windows 10+
72-
if (advanced_display && !(dwMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING)) {
73-
SetConsoleMode(hConsole, dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
74+
// Check conditions combined to reduce nesting
75+
if (advanced_display && !(dwMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) &&
76+
!SetConsoleMode(hConsole, dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING)) {
77+
advanced_display = false;
7478
}
7579
// Set console output codepage to UTF8
7680
SetConsoleOutputCP(CP_UTF8);

0 commit comments

Comments
 (0)