File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 19
19
#include < signal.h>
20
20
#endif
21
21
22
+ #if defined (_WIN32)
23
+ #pragma comment(lib,"kernel32.lib")
24
+ extern " C" __declspec(dllimport) void * __stdcall GetStdHandle (unsigned long nStdHandle);
25
+ extern " C" __declspec(dllimport) int __stdcall GetConsoleMode (void * hConsoleHandle, unsigned long * lpMode);
26
+ extern " C" __declspec(dllimport) int __stdcall SetConsoleMode (void * hConsoleHandle, unsigned long dwMode);
27
+ #endif
28
+
22
29
#define ANSI_COLOR_RED " \x1b [31m"
23
30
#define ANSI_COLOR_GREEN " \x1b [32m"
24
31
#define ANSI_COLOR_YELLOW " \x1b [33m"
@@ -933,6 +940,13 @@ int main(int argc, char ** argv) {
933
940
934
941
// set the color for the prompt which will be output initially
935
942
if (params.use_color ) {
943
+ #if defined (_WIN32)
944
+ // Enable ANSI colors on Windows 10+
945
+ unsigned long dwMode = 0 ;
946
+ void * hConOut = GetStdHandle ((unsigned long )-11 ); // STD_OUTPUT_HANDLE (-11)
947
+ if (hConOut && hConOut != (void *)-1 && GetConsoleMode (hConOut, &dwMode))
948
+ SetConsoleMode (hConOut, dwMode | 0x4 ); // ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4)
949
+ #endif
936
950
printf (ANSI_COLOR_YELLOW);
937
951
}
938
952
You can’t perform that action at this time.
0 commit comments