Last active
December 21, 2020 21:44
-
-
Save SasLuca/dd552b09f3c4457f5b7faa8d483a54dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "terminal_colors.h" | |
#ifdef WIN32 | |
#include "windows.h" | |
/* | |
Sources: | |
https://github.com/microsoft/WSL/issues/1173#issuecomment-254250445 | |
https://github.com/microsoft/WSL/issues/1173 | |
https://stackoverflow.com/questions/52607960/how-can-i-enable-virtual-terminal-processing | |
https://stackoverflow.com/questions/38772468/setconsolemode-and-enable-virtual-terminal-processing | |
*/ | |
bool platform_ensure_colors_in_terminal_work() | |
{ | |
HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); | |
DWORD mode = 0; | |
GetConsoleMode(std_out, &mode); | |
mode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING; | |
bool success = SetConsoleMode(std_out, mode); | |
return success; | |
} | |
#else | |
/* other platforms seem to differ from the microsoft ordained standard for some reason */ | |
bool platform_ensure_colors_in_terminal_work() { return true; } | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef ENSURE_TERMINAL_COLORS_H | |
#define ENSURE_TERMINAL_COLORS_H | |
bool platform_ensure_colors_in_terminal_work(); | |
#endif // ENSURE_TERMINAL_COLORS_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment