-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (49 loc) · 937 Bytes
/
main.cpp
File metadata and controls
56 lines (49 loc) · 937 Bytes
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
#include "TextBuffer.hpp"
#include "PieceTable.hpp"
int main()
{
// initialize ncurses screen
initscr();
raw();
noecho();
scrollok(stdscr, TRUE); // Enable scrolling
int ch;
PieceTable pt;
while ((ch = getch()) != '`' && ch != KEY_F(1))
{
if (ch == KEY_BACKSPACE || ch == 127)
{
pt.undo();
}
else
{
pt.insert(std::string(1, ch));
}
// clear screen
erase();
// write everything in the buffer to screen
int row = 0;
int col = 0;
for (char ch : pt.getText())
{
if (ch == '\n')
{
// Move to the next line
row++;
col = 0;
move(row, col);
}
else
{
// Print the character
mvprintw(row, col, "%c", ch);
col++;
}
}
refresh();
}
std::string buffer_contents = pt.getText();
endwin();
std::cout << buffer_contents << std::endl;
return EXIT_SUCCESS;
}