diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-05-26 03:25:05 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-05-26 03:25:05 -0300 |
commit | 3ae52c8cfdb1f8d6e887e9c8c980bbbec7fcb246 (patch) | |
tree | 8e0bef9529ea4802b06d5d95ad5c749c2662acaa /jet.cpp | |
parent | 98280238383dc390207827d09dc92e0459229134 (diff) | |
download | jet-3ae52c8cfdb1f8d6e887e9c8c980bbbec7fcb246.tar.gz jet-3ae52c8cfdb1f8d6e887e9c8c980bbbec7fcb246.zip |
Add partial support for utf-8
Diffstat (limited to 'jet.cpp')
-rw-r--r-- | jet.cpp | 45 |
1 files changed, 9 insertions, 36 deletions
@@ -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(); |