1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
// Ansi Version
enum colors { BLACK = 0, RED, GREEN, YELLOW, BLUE, PURPLE, CYAN, GREY,
LIGHTGREY, LIGHTRED, LIGHTGREEN, LIGHTYELLOW, LIGHTBLUE,
LIGHTPURPLE, LIGHTCYAN, WHITE, DEFAULT };
void consolecolor(colors textColor = DEFAULT, colors backgroundColor = DEFAULT) {
// Set default foreground color
if (textColor == DEFAULT)
std::cout << "\x1B[39m";
// Set bright foreground color
else if (textColor > GREY) {
// Set bright mode
std::cout << "\x1B[1m";
// Set color
std::cout << "\x1B[3" << textColor - LIGHTGREY << "m";
}
// Set normal foreground color
else {
// Set normal mode
std::cout << "\x1B[22m";
// Set color
std::cout << "\x1B[3" << textColor << "m";
}
// Set default background color
if (backgroundColor == DEFAULT)
std::cout << "\x1B[49m";
// Set bright background color
else if (backgroundColor > GREY) {
// Set bright mode
std::cout << "\x1B[1m";
// Set color
std::cout << "\x1B[4" << backgroundColor - LIGHTGREY << "m";
}
// Set normal background color
else {
// Set normal mode
std::cout << "\x1B[22m";
// Set color
std::cout << "\x1B[4" << backgroundColor << "m";
}
}
// Use
// setconsolecolor(BLACK, GREY);
// Same result as above
// Can be any value in enum, otherwise it just returns false without doing anything
|