-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.cpp
52 lines (42 loc) · 1.01 KB
/
Window.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
// Window.cpp
#include <iostream>
#include "Window.h"
using namespace std;
Window::Window()
{
}
// Prints text to terminal in colour using ANSI escape sequences
void Window::Format(int color)
{
// Default background/foreground colours as zero
int bg = 0;
switch(color)
{
case 0: {bg = 0; break;} // Black
case 1: {bg = 41; break;} // Red
case 2: {bg = 42; break;} // Green
case 3: {bg = 43; break;} // Yellow
case 4: {bg = 44; break;} // Blue
case 5: {bg = 45; break;} // Magenta
case 6: {bg = 46; break;} // Cyan
case 7: {bg = 47; break;} // White
case 8: {cout << "\033[48;2;255;165;0m"; return;} // Orange (RGB)
}
cout << "\033[0;" << bg << "m";
}
// Returns a % b as positive
unsigned Window::Modulo(int a, unsigned b)
{
int mod = a % (int)b;
if (mod < 0)
mod += b;
return mod;
}
// Toggles terminal cursor visibility, ANSI escape sequence from: https://gist.github.com/drm/1688256
void Window::ShowCursor(bool visible)
{
cout << "\033[?25" << (visible ? "h" : "l");
}
Window::~Window()
{
}