From 98280238383dc390207827d09dc92e0459229134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 24 May 2020 05:35:00 -0300 Subject: Rewrite in c++ --- test/page.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/page.cpp (limited to 'test/page.cpp') diff --git a/test/page.cpp b/test/page.cpp new file mode 100644 index 0000000..d0a4d54 --- /dev/null +++ b/test/page.cpp @@ -0,0 +1,48 @@ +#include + +#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; +} -- cgit v1.2.3