Newer
Older
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <string>
#include <iostream>
// ANSI codes
namespace console {
void consolecursor(bool show = true) {
if (show)
std::cout << "\x1B[25h";
else
std::cout << "\x1B[25l";
}
bool gotoxy(unsigned short x = 1, unsigned short y = 1) {
if ((x == 0) || (y == 0))
return false;
std::cout << "\x1B[" << y << ";" << x << "H";
}
void clearscreen(bool moveToStart = true) {
std::cout << "\x1B[2J";
if (moveToStart)
gotoxy(1,1);
}
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";
}
}
void setconsoletextcolor(colors textColor) {
// Set bright foreground color
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";
}
}
// Numerical color setter
/*bool setconsoletextcolor(int textcolor = -1) {
if (((textcolor < 0) || (textcolor > 7)) && (textcolor != -1))
return false;
std::cout << "\x1B[3" << textcolor << "m";
return true;
}*/
void eraser() {
std::cout << "\033[A\033[2K";
}
}