Last active
August 30, 2017 03:02
-
-
Save garrettsickles/22844b0befebbee3a523bb6544c03a03 to your computer and use it in GitHub Desktop.
Cross Platform Console Colorization (C, C++)
This file contains 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
// --------------------------------------------------------------- // | |
// Need To Know | |
// _MSC_VER: Microsoft C/C++ Compiler | |
// --------------------------------------------------------------- // | |
// Microsoft C/C++ Compiler | |
#if defined (_MSC_VER) | |
// Console Control | |
#include <Windows.h> | |
// Text Colors | |
#define TEXT_COLOR_RED 0x0C | |
#define TEXT_COLOR_GREEN 0x0A | |
#define TEXT_COLOR_CYAN 0x0B | |
#define TEXT_COLOR_WHITE 0x07 | |
// Set console text color to one of the previous 4 colors | |
#define SET_TEXT_COLOR(color) do {\ | |
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);\ | |
SetConsoleTextAttribute(hConsole, color);\ | |
} while(0) | |
// Unix | |
#else | |
// Console Control | |
#include <sys/ioctl.h> | |
// Text Colors | |
#define TEXT_COLOR_RED "\033[1m\033[31m" | |
#define TEXT_COLOR_GREEN "\033[1m\033[32m" | |
#define TEXT_COLOR_CYAN "\033[1m\033[36m" | |
#define TEXT_COLOR_WHITE "\033[0m\033[37m" | |
// Set console text color to one of the previous 4 colors | |
#define SET_TEXT_COLOR(color) do {\ | |
printf(color);\ | |
} while(0) | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment