-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.cpp
More file actions
95 lines (84 loc) · 1.65 KB
/
console.cpp
File metadata and controls
95 lines (84 loc) · 1.65 KB
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
#include <curses.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
class ConsoleWindow
{
WINDOW *window;
int xpos, ypos;
int xsize, ysize;
public:
ConsoleWindow(int x,int y,int width,int height);
void write(std::string string);
WINDOW * getScr();
};
ConsoleWindow::ConsoleWindow(int x,int y,int width,int height)
{
xpos = x;
ypos = y;
xsize = width;
ysize = height;
window = newwin(width, height, x, y);
}
void ConsoleWindow::write(std::string string)
{
char cstr[80];
for(int i = 0; i < string.length() && i < 80; i++){
cstr[i] = string.at(i);
}
wprintw(window, cstr);
}
WINDOW * ConsoleWindow::getScr()
{
return window;
}
void init()
{
initscr();
noecho();
cbreak();
raw();
keypad(stdscr, TRUE);
}
void print(int x, int y, std::string string, WINDOW *scr)
{
char cstr[80];
for(int i = 0; i < string.length() && i < 80; i++){
cstr[i] = string.at(i);
}
mvwprintw(scr, x,y, cstr);
}
std::string getString(WINDOW *scr)
{
std::string str;
int key;
while((char)key != '\n')
{
key = wgetch(scr);
if(key == KEY_BACKSPACE)
{
str = str.substr(0, str.size() -1);
}
else
{
str += (char)key;
}
}
return str;
}
int main()
{
std::cout << "start" << std::endl;
std::string string;
init();
refresh();
ConsoleWindow testwindow = ConsoleWindow(0,0,10,10);
ConsoleWindow bananawindow = ConsoleWindow(10,10,10,10);
testwindow.write("hello my name is banana cool bro");
bananawindow.write("this is another window yo");
wrefresh(testwindow.getScr());
wrefresh(bananawindow.getScr());
getch();
endwin();
return 0;
}