-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerminal.h
56 lines (50 loc) · 1.26 KB
/
Terminal.h
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
/////////////////////////////////
// DO NOT MODIFY THIS FILE!!!! //
/////////////////////////////////
#ifndef TERMINAL_H
#define TERMINAL_H
#include <string>
#include <iostream>
static const char *CSI = "\x1b[";
// The Terminal class abstracts away things we need to draw in the terminal.
class Terminal
{
public:
// The possible colors. Note that foreground colors can also be 'bright',
// adding another 8 colors
enum Color
{
BLACK = 0,
RED,
GREEN,
YELLOW,
BLUE,
MAGENTA,
CYAN,
WHITE,
DEFAULT_COLOR = 9
};
// Set the foreground color for the next piece of text, keeping the
// background color as is.
static void color_fg( bool bright , Color color )
{
std::cout << CSI << 30 + color << (bright ? ";1" : "") << "m";
}
// Set the background color for the next piece of text, keeping the
// foreground color as-is.
static void color_bg( Color color )
{
std::cout << CSI << 40 + color << "m";
}
// Set both background and foreground colors at the same time.
static void color_all( bool bright , Color foreColor , Color backColor )
{
std::cout << CSI << 30 + foreColor << (bright ? ";1;" : ";") << 40 + backColor << "m";
}
// Reset the color to the default
static void set_default( void )
{
std::cout << CSI << "0m";
}
};
#endif // TERMINAL_H