/
term-colors.cpp
56 lines (53 loc) · 1.24 KB
/
term-colors.cpp
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
// http://www.termsys.demon.co.uk/vtansi.htm
//
// Set Display Attributes
//
// Set Attribute Mode <ESC>[{attr1};...;{attrn}m
//
// Sets multiple display attribute settings. The following lists standard attributes:
//
// 0 Reset all attributes
// 1 Bright
// 2 Dim
// 4 Underscore
// 5 Blink
// 7 Reverse
// 8 Hidden
//
// Foreground Colours
// 30 Black
// 31 Red
// 32 Green
// 33 Yellow
// 34 Blue
// 35 Magenta
// 36 Cyan
// 37 White
//
// Background Colours
// 40 Black
// 41 Red
// 42 Green
// 43 Yellow
// 44 Blue
// 45 Magenta
// 46 Cyan
// 47 White
#include <iostream>
using namespace std;
int main()
{
const char *colors[] ={"Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White"};
for(int fg = 30; fg <= 37; fg++) {
for(int bg = 40; bg <= 47; bg++) {
// Set Attribute Mode <ESC>[{attr1};...;{attrn}m
// Are attr values binary values or ascii integers?
// Ascii values, I think
cout << "\0x1b[1;" << fg << ';' << bg << 'm';
cout
<< "fg " << int(fg) << " " << colors[fg&7] << " "
<< "bg " << int(bg) << " " << colors[bg&7] << " "
;
cout << "\033[" << "\0" << 'm';
}}
}