summaryrefslogtreecommitdiff
path: root/jet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'jet.cpp')
-rw-r--r--jet.cpp45
1 files changed, 9 insertions, 36 deletions
diff --git a/jet.cpp b/jet.cpp
index 27d3f74..ff1da36 100644
--- a/jet.cpp
+++ b/jet.cpp
@@ -1,50 +1,26 @@
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
+#include <locale.h>
#include <curses.h>
+#define PAGE_SIZE 16
#include "page.cpp"
#include "point.cpp"
+#include "buffer.cpp"
#define NORMAL_MODE 0
#define INSERT_MODE 1
-struct Buffer {
- const char *name;
- Point start;
- Point cursor;
-
- Buffer(const char *name) : name(name), start(new Page()), cursor(start) {}
-
- void prev_line(int window_width) {
- cursor--;
- cursor--;
- cursor.rseek('\n', window_width - 2);
- if (cursor.element() == '\n') {
- cursor++;
- }
- }
-
- void next_line(int window_width) {
- cursor.seek('\n', window_width);
- if (cursor.element() == '\n') {
- cursor++;
- }
- }
-
-};
-
int main(int argc, char *argv[]) {
+ setlocale(LC_ALL, "");
initscr();
cbreak();
noecho();
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
- Buffer buffer = Buffer("test");
- Point window_start = buffer.start;
+ Buffer buffer("test");
+ Point window_start(buffer.start);
if (argc > 1) {
FILE *f = fopen(argv[1], "r");
@@ -66,12 +42,12 @@ int main(int argc, char *argv[]) {
clear();
int x = -1, y = -1;
- Point window_end = window_start;
- while (window_end.element() && getcury(stdscr) < window_height - 1) {
+ Point window_end(window_start);
+ while (!window_end.at_end() && getcury(stdscr) < window_height - 1) {
if (window_end == buffer.cursor) {
getyx(stdscr, y, x);
}
- addch(window_end.element());
+ printw("%lc", window_end.element());
window_end++;
}
if (x > -1 && y > -1) {
@@ -113,9 +89,6 @@ int main(int argc, char *argv[]) {
buffer.cursor.push(input);
}
}
- if (buffer.cursor.element() == 0) {
- buffer.cursor--;
- }
}
endwin();