-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbbmain.cpp
More file actions
71 lines (65 loc) · 2.37 KB
/
bbmain.cpp
File metadata and controls
71 lines (65 loc) · 2.37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bbmain.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: Roger Ndaba <rogerndaba@gmil.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/15 12:26:54 by Roger Ndaba #+# #+# */
/* Updated: 2019/06/15 17:05:16 by Roger Ndaba ### ########.fr */
/* */
/* ************************************************************************** */
#include <ncurses.h>
#include <unistd.h>
#include <iostream>
#include <limits>
#include <regex>
#include <string>
#include <vector>
void printlines(std::vector<std::string> lines) {
for (long i = 0; i < (long)lines.size(); i++) {
std::string buf; // Have a buffer string
std::stringstream ss(lines[i]); // Insert the string into a stream
while (ss >> buf) {
if (std::regex_match(buf, std::regex("print")))
attron(COLOR_PAIR(1));
printw("%s ", buf.c_str());
refresh();
attroff(COLOR_PAIR(1));
}
printw("\b\n");
}
}
int main() {
std::vector<std::string> lines;
std::string buffer;
int ch;
initscr(); /* Start curses mode */
keypad(stdscr, TRUE); /* We get F1, F2 etc.. */
noecho(); /* Don't echo() while we do getch */
start_color();
init_pair(1, COLOR_RED, COLOR_BLACK);
clear();
while ((ch = getch())) {
if (ch == '\n' && !buffer.empty()) {
lines.push_back(buffer);
if (buffer == "exit") {
clear();
refresh();
printlines(lines);
printw(buffer.c_str());
sleep(10);
break;
}
buffer = "";
} else {
buffer.push_back(ch);
}
clear();
refresh();
printlines(lines);
printw(buffer.c_str());
}
endwin();
return 0;
}