-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerminalEngine.cpp
54 lines (52 loc) · 1.43 KB
/
TerminalEngine.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
#include <iostream>
#include <vector>
#include <ncurses.h>
#include <string>
#include <unistd.h>
using namespace std;
class TerminalEngine {
public:
int terminal_xSize;
int terminal_ySize;
int y_count = 1;
TerminalEngine (bool no_delay = true, bool hide_cursor = true, bool echo = false) {
initscr();
if (no_delay) nodelay(stdscr, TRUE);
getmaxyx(stdscr, terminal_ySize, terminal_xSize);
if (hide_cursor) {
curs_set(0);
}
if (!has_colors()) {
endwin();
throw invalid_argument("Terminal doesn't support colors");
}
if (!echo) noecho();
keypad(stdscr, TRUE);
cbreak();
start_color();
};
void set_attr (int index, int colorOne, int colorTwo) {
init_pair(index, colorOne, colorTwo);
}
int get_key_pressed () {
return getch();
}
void print (string text, int xCoord, int yCoord, int attr = -1, bool bold = false) {
if (attr != -1) attron(COLOR_PAIR(attr));
if (bold) attron(A_BOLD);
if (yCoord == -1) mvprintw(y_count, xCoord, text.c_str());
else mvprintw(yCoord, xCoord, text.c_str());
if (bold) attroff(A_BOLD);
if (attr != -1) attroff(COLOR_PAIR(attr));
refresh();
y_count++;
}
void end () {
refresh();
getch();
endwin();
}
void wait (int millisec) {
usleep(millisec);
}
};