diff options
Diffstat (limited to 'test/point.c')
-rw-r--r-- | test/point.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/point.c b/test/point.c new file mode 100644 index 0000000..9c4abc9 --- /dev/null +++ b/test/point.c @@ -0,0 +1,57 @@ +#include <curses.h> + +#define PAGE_SIZE 16 +#include "../page.c" +#include "../point.c" + +int main() { + int exit = 0; + struct page *page = new_page(); + struct point point = {page, 0}; + + 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->elements[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->elements[i]); + } + iter = iter->next; + } + + int input = getch(); + switch (input) { + case KEY_LEFT: + move_point_backward(&point); + align_gap(&point); + break; + case KEY_RIGHT: + move_point_forward(&point); + align_gap(&point); + break; + case KEY_BACKSPACE: + delete_at_point(&point); + break; + default: + insert_at_point(&point, input); + } + } + + endwin(); + return 0; +} |