-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.cpp
More file actions
169 lines (144 loc) · 3.43 KB
/
Copy pathWindow.cpp
File metadata and controls
169 lines (144 loc) · 3.43 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "Window.h"
#include <curses.h>
#include <clocale>
#include <string>
Window::Window(void) {
setlocale(LC_ALL, "UTF-8");
initscr();
cbreak();
noecho();
intrflush(stdscr, false);
keypad(stdscr, true);
start_color();
init_pair(1 ,COLOR_BLACK, COLOR_WHITE);
getmaxyx(stdscr, row, col);
top = subwin(stdscr, 1, col, 0, 0);
bot = subwin(stdscr, 1, col, row - 1, 0);
vSize = 0;
curs_set(0);
cursorPos = 0;
funcDisplay = NULL;
}
WINDOW *Window::createNewWin(int height, int width, int starty, int startx)
{
WINDOW *localWin;
localWin = newwin(height, width, starty, startx);
wrefresh(localWin);
return localWin;
}
Window::~Window(void) {
delwin(top);
delwin(bot);
endwin();
}
int Window::getChar(void) {
return wgetch(stdscr);
}
void Window::putChar(int c) {
mvwaddch(stdscr, 5, 5, c);
}
void Window::addStrToBuffer(std::string str) {
vStr.push_back(str);
vSize++;
}
void Window::print(void) {
std::vector<std::string>::const_iterator it;
int currentLine;
currentLine = 1;
for (it = vStr.begin(); it != vStr.end(); it++) {
if (cursorPos == currentLine - 1) {
wattron(stdscr, A_STANDOUT);
}
mvwprintw(stdscr, currentLine, 3, (*it).c_str());
if (cursorPos == currentLine - 1) {
wattroff(stdscr, A_STANDOUT);
}
currentLine++;
}
}
void Window::updateCursorPos(int c) {
int curCursorPos = cursorPos;
if (c == KEY_UP) {
cursorPos--;
} else if (c == KEY_DOWN) {
cursorPos++;
}
if (cursorPos > vSize - 1) {
cursorPos = 0;
}
if (cursorPos < 0)
cursorPos = vSize - 1;
if (vSize > 0) {
mvwprintw(stdscr, curCursorPos + 1, 3, vStr[curCursorPos].c_str());
wattron(stdscr, A_STANDOUT);
mvwprintw(stdscr, cursorPos + 1, 3, vStr[cursorPos].c_str());
wattroff(stdscr, A_STANDOUT);
}
}
void Window::welcome(void) {
static const std::string welcomeStr = "Manalink";
werase(top);
werase(bot);
wbkgd(top, COLOR_PAIR(1));
mvwprintw(top, 0, col / 2 - (welcomeStr.length() / 2), welcomeStr.c_str());
wbkgd(bot, COLOR_PAIR(1));
mvwprintw(bot, 0, col / 2 - (welcomeStr.length() / 2), welcomeStr.c_str());
wrefresh(bot);
}
void Window::displayBot(const std::string &str) {
werase(bot);
mvwprintw(bot, 0, col / 2 - (str.length() / 2), str.c_str());
wrefresh(bot);
}
const int Window::getCursorPos(void) const {
return cursorPos;
}
void Window::clear(void) {
werase(stdscr);
}
void Window::clearList(void) {
cursorPos = 0;
vStr.clear();
vSize = 0;
}
void Window::printLink(pairString p) {
wattron(stdscr, A_UNDERLINE);
mvwprintw(stdscr, 2, col / 2 - (p.first.length() / 2), p.first.c_str());
wattroff(stdscr, A_UNDERLINE);
mvwprintw(stdscr, 5, 3, p.second.c_str());
}
std::string *Window::getString(int esc) {
bool flag;
int c;
std::string *buffer;
buffer = new std::string;
flag = true;
while (flag) {
c = this->getChar();
if (c == esc) {
flag = false;
} else {
if (std::isprint(c) != 0) {
buffer->append(1, static_cast<char>(c));
(this->*funcDisplay)(buffer);
}
}
}
return buffer;
}
void Window::writingBotManagement(std::string *buff) {
std::string str;
str = "New category: ";
if (str.size() > COLS - 5) {
str = *buff;
} else {
str += *buff;
}
if (str.size() > COLS - 5) {
str = str.substr(str.size() - COLS + 5, COLS - 5);
}
this->displayBot(str);
}
void Window::setupWritingBot(void) {
funcDisplay = &Window::writingBotManagement;
}