blob: 0d4dd33dcb1c1ac1e909cfe82f74bd20352150b0 (
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
49
50
51
52
53
54
|
#include <curses.h>
#include "../page.c"
int main() {
int exit = 0;
struct page *page = new_page();
struct point point = {0};
point.current_page = page;
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
while (!exit) {
clear();
struct page *iter = page;
while (iter) {
addch('|');
for (int i = 0; i < iter->gap_start; i++) {
addch(iter->buffer[i]);
}
for (int i = iter->gap_start; i < iter->gap_end; i++) {
addch('_');
}
for (int i = iter->gap_end; i < PAGE_SIZE; i++) {
addch(iter->buffer[i]);
}
iter = iter->next;
}
int input = getch();
switch (input) {
case KEY_LEFT:
move_point_backward(&point);
break;
case KEY_RIGHT:
move_point_forward(&point);
break;
case KEY_BACKSPACE:
delete_at_point(&point);
break;
default:
insert_at_point(&point, input);
}
}
endwin();
return 0;
}
|