summaryrefslogtreecommitdiff
path: root/test/page.cpp
blob: d0a4d543dd95c724ae3546c9c86f72ccbb8454e1 (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>

#define PAGE_SIZE 32
#include "../page.cpp"

int main() {
	int exit = 0;
	Page page = Page();

	initscr();
	cbreak();
	noecho();
	nonl();
	intrflush(stdscr, FALSE);
	keypad(stdscr, TRUE);

	while (!exit) {
		clear();

		for (int i = 0; i < page.gap_start; i++) {
			addch(page.elements[i]);
		}
		for (int i = page.gap_start; i < page.gap_end; i++) {
			addch('.');
		}
		for (int i = page.gap_end; i < PAGE_SIZE; i++) {
			addch(page.elements[i]);
		}

		int input = getch();
		switch (input) {
			case KEY_LEFT:
				page--;
				break;
			case KEY_RIGHT:
				page++;
				break;
			case KEY_BACKSPACE:
				page.pop();
				break;
			default:
				page.push(input);
		}
	}

	endwin();
	return 0;
}