summaryrefslogtreecommitdiff
path: root/test/point.cpp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-05-24 05:35:00 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-05-24 05:35:00 -0300
commit98280238383dc390207827d09dc92e0459229134 (patch)
treee2bc7c0877289165463dd6f9c2e77b570b22e29c /test/point.cpp
parentd37027bbd7ac13fdd0f1e2f01e1ec4b75b6c9588 (diff)
downloadjet-98280238383dc390207827d09dc92e0459229134.tar.gz
jet-98280238383dc390207827d09dc92e0459229134.zip
Rewrite in c++
Diffstat (limited to 'test/point.cpp')
-rw-r--r--test/point.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/point.cpp b/test/point.cpp
new file mode 100644
index 0000000..edf4492
--- /dev/null
+++ b/test/point.cpp
@@ -0,0 +1,76 @@
+#include <curses.h>
+
+#define PAGE_SIZE 16
+#include "../page.cpp"
+#include "../point.cpp"
+
+int main() {
+ int exit = 0;
+ Page *page = new Page();
+ Point point = Point(page);
+
+ initscr();
+ start_color();
+ cbreak();
+ noecho();
+ nonl();
+ intrflush(stdscr, FALSE);
+ keypad(stdscr, TRUE);
+
+#define black 20
+#define red 21
+#define green 22
+ init_color(black, 0, 0, 0);
+ init_color(red, 1000, 0, 0);
+ init_color(green, 0, 1000, 0);
+ init_pair(1, red, black);
+ init_pair(2, green, black);
+
+ while (!exit) {
+ clear();
+
+ Page *iter = page;
+ while (iter) {
+ if (iter == point.page && iter->gap_end == point.index_to_offset()) {
+ attron(COLOR_PAIR(1));
+ } else {
+ attron(COLOR_PAIR(2));
+ }
+ 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;
+ attroff(COLOR_PAIR(1));
+ attroff(COLOR_PAIR(2));
+ }
+
+ int input = getch();
+ switch (input) {
+ case '':
+ exit = 1;
+ break;
+ case KEY_LEFT:
+ point--;
+ point.align_gap();
+ break;
+ case KEY_RIGHT:
+ point++;
+ point.align_gap();
+ break;
+ case KEY_BACKSPACE:
+ point.pop();
+ break;
+ default:
+ point.push(input);
+ }
+ }
+
+ endwin();
+ return 0;
+}