summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile6
-rw-r--r--test/page.c48
-rw-r--r--test/point.c57
4 files changed, 113 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 2edc120..30702f2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
jet
+page
+point
diff --git a/Makefile b/Makefile
index 271b929..be264eb 100644
--- a/Makefile
+++ b/Makefile
@@ -2,3 +2,9 @@ FLAGS=-ggdb -O0 -fno-builtin -Wall -lcurses
jet: Makefile *.c
gcc $(FLAGS) jet.c -o jet
+
+page: Makefile page.c test/page.c
+ gcc $(FLAGS) test/page.c -o page
+
+point: Makefile point.c test/point.c
+ gcc $(FLAGS) test/point.c -o point
diff --git a/test/page.c b/test/page.c
new file mode 100644
index 0000000..f558fc6
--- /dev/null
+++ b/test/page.c
@@ -0,0 +1,48 @@
+#include <curses.h>
+
+#define PAGE_SIZE 32
+#include "../page.c"
+
+int main() {
+ int exit = 0;
+ struct page *page = new_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:
+ move_gap_backward(page);
+ break;
+ case KEY_RIGHT:
+ move_gap_forward(page);
+ break;
+ case KEY_BACKSPACE:
+ delete_at_gap(page);
+ break;
+ default:
+ insert_at_gap(page, input);
+ }
+ }
+
+ endwin();
+ return 0;
+}
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;
+}