summaryrefslogtreecommitdiff
path: root/test
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
parentd37027bbd7ac13fdd0f1e2f01e1ec4b75b6c9588 (diff)
downloadjet-98280238383dc390207827d09dc92e0459229134.tar.gz
jet-98280238383dc390207827d09dc92e0459229134.zip
Rewrite in c++
Diffstat (limited to 'test')
-rw-r--r--test/page.cpp (renamed from test/page.c)22
-rw-r--r--test/point.cpp (renamed from test/point.c)24
2 files changed, 23 insertions, 23 deletions
diff --git a/test/page.c b/test/page.cpp
index f558fc6..d0a4d54 100644
--- a/test/page.c
+++ b/test/page.cpp
@@ -1,11 +1,11 @@
#include <curses.h>
#define PAGE_SIZE 32
-#include "../page.c"
+#include "../page.cpp"
int main() {
int exit = 0;
- struct page *page = new_page();
+ Page page = Page();
initscr();
cbreak();
@@ -17,29 +17,29 @@ int main() {
while (!exit) {
clear();
- for (int i = 0; i < page->gap_start; i++) {
- addch(page->elements[i]);
+ for (int i = 0; i < page.gap_start; i++) {
+ addch(page.elements[i]);
}
- for (int i = page->gap_start; i < page->gap_end; 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]);
+ 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);
+ page--;
break;
case KEY_RIGHT:
- move_gap_forward(page);
+ page++;
break;
case KEY_BACKSPACE:
- delete_at_gap(page);
+ page.pop();
break;
default:
- insert_at_gap(page, input);
+ page.push(input);
}
}
diff --git a/test/point.c b/test/point.cpp
index 0902f47..edf4492 100644
--- a/test/point.c
+++ b/test/point.cpp
@@ -1,13 +1,13 @@
#include <curses.h>
#define PAGE_SIZE 16
-#include "../page.c"
-#include "../point.c"
+#include "../page.cpp"
+#include "../point.cpp"
int main() {
int exit = 0;
- struct page *page = new_page();
- struct point point = {page, 0};
+ Page *page = new Page();
+ Point point = Point(page);
initscr();
start_color();
@@ -29,9 +29,9 @@ int main() {
while (!exit) {
clear();
- struct page *iter = page;
+ Page *iter = page;
while (iter) {
- if (iter == point.page) {
+ if (iter == point.page && iter->gap_end == point.index_to_offset()) {
attron(COLOR_PAIR(1));
} else {
attron(COLOR_PAIR(2));
@@ -56,18 +56,18 @@ int main() {
exit = 1;
break;
case KEY_LEFT:
- move_point_backward(&point);
- align_gap(&point);
+ point--;
+ point.align_gap();
break;
case KEY_RIGHT:
- move_point_forward(&point);
- align_gap(&point);
+ point++;
+ point.align_gap();
break;
case KEY_BACKSPACE:
- delete_at_point(&point);
+ point.pop();
break;
default:
- insert_at_point(&point, input);
+ point.push(input);
}
}