-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (47 loc) · 1.2 KB
/
main.cpp
File metadata and controls
54 lines (47 loc) · 1.2 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
#include <ncurses.h>
#include "utils/gap.cpp"
int main() {
initscr();
raw();
keypad(stdscr, TRUE);
noecho();
GapBuffer editor(1000);
int ch;
while (true) {
// Render
clear(); // Clear old screen
editor.display(); // Display text
refresh(); // Refresh screen
move(0, editor.getGapStart()); // Move cursor to current gap start
refresh(); // Refresh screen for render cursor
// Input
ch = getch();
// Logic event
if (ch == 'q') break;
switch (ch)
{
// key left
case KEY_LEFT:
editor.moveLeft();
break;
// key right
case KEY_RIGHT:
editor.moveRight();
break;
// backspace
case KEY_BACKSPACE:
// case: some device backspace ascii is 127
case 127:
editor.backspace();
break;
default:
// Normal character
if (ch >= 10 && ch <= 126) {
editor.insert((char) ch);
}
break;
}
}
endwin();
return 0;
}