diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-27 10:09:52 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-27 10:09:52 -0300 |
commit | a8b879b9e91d29eb8d3172a445b7501ffd3a83c2 (patch) | |
tree | e6fffe37fb3fefd3a86cf2957f23f2c940e25852 /jet.c | |
parent | 85b84f23d22a84f9961a66beed99df489478dd86 (diff) | |
download | jet-a8b879b9e91d29eb8d3172a445b7501ffd3a83c2.tar.gz jet-a8b879b9e91d29eb8d3172a445b7501ffd3a83c2.zip |
Add basic editing capabilities
Cursor is now visible and can insert, delete and move across the buffer.
Diffstat (limited to 'jet.c')
-rw-r--r-- | jet.c | 33 |
1 files changed, 25 insertions, 8 deletions
@@ -25,12 +25,13 @@ int main(int argc, char *argv[]) { while ((c = fgetc(f)) != EOF) { insert_at_point(&cursor, c); } + cursor.page = page; + cursor.index = 0; fclose(f); } int window_height = getmaxy(stdscr); int current_line = 0; - int old_line = -1; int number_of_lines = 0; for (struct point i = {page, 0}; !at_eof(&i); move_point_forward(&i)) { @@ -38,17 +39,21 @@ int main(int argc, char *argv[]) { } while (1) { - if (old_line != current_line) { - clear(); + clear(); - int iter_line = 0; - for (struct point i = {page, 0}; !at_eof(&i) && iter_line < window_height + current_line; move_point_forward(&i)) { - if (iter_line >= current_line) addch(element(&i)); - if (element(&i) == '\n') iter_line++; + int x = -1, y = -1; + int iter_line = 0; + for (struct point i = {page, 0}; !at_eof(&i) && iter_line < window_height + current_line; move_point_forward(&i)) { + if (same_location(&i, &cursor)) { + getyx(stdscr, y, x); } + if (iter_line >= current_line) addch(element(&i)); + if (element(&i) == '\n') iter_line++; + } + if (x > -1 && y > -1) { + move(y, x); } - old_line = current_line; int input = getch(); switch (input) { @@ -57,6 +62,18 @@ int main(int argc, char *argv[]) { break; case KEY_DOWN: if (current_line < number_of_lines - window_height) current_line++; + break; + case KEY_LEFT: + move_point_backward(&cursor); + break; + case KEY_RIGHT: + move_point_forward(&cursor); + break; + case KEY_BACKSPACE: + delete_at_point(&cursor); + break; + default: + insert_at_point(&cursor, input); } } |