blob: 8dd2c9030a1e1117918f8135249cba26d1e354ff (
plain)
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
|
#include <curses.h>
#include "../page.c"
int main() {
int exit = 0;
struct page *p = new_page();
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
while (!exit) {
int gap_start = p->gap_start - p->buffer;
int gap_end = p->gap_end - p->buffer;
for (int i = 0; i < gap_start; i++) {
addch(p->buffer[i]);
}
for (int i = gap_start; i < gap_end; i++) {
addch('_');
}
for (int i = gap_end; i < PAGE_SIZE; i++) {
addch(p->buffer[i]);
}
int input = getch();
clear();
switch (input) {
case KEY_LEFT:
move_gap(p, -1);
break;
case KEY_RIGHT:
move_gap(p, 1);
break;
case KEY_BACKSPACE:
delete_from_page(p);
break;
default:
insert_into_page(p, input);
}
}
endwin();
return 0;
}
|