From 4d10bce15ce052e364392d94c3a3a0af602b8e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Wed, 15 Jul 2020 19:14:40 -0300 Subject: Show cursor and update it when moving --- client.cpp | 6 +----- jet2.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/client.cpp b/client.cpp index 80d784c..bed62c5 100644 --- a/client.cpp +++ b/client.cpp @@ -52,11 +52,7 @@ struct Client { Point window_end(window_start); for (int i = 0; i < window_h; i++) { for (int j = 0; j < window_w; j++) { - if (window_end == cursor) { - view[pos(j, i)] = '$'; - } else { - view[pos(j, i)] = window_end.element(); - } + view[pos(j, i)] = window_end.element(); if (window_end.element() == '\n') { for (int k = j + 1; k < window_w; k++) { view[pos(k, i)] = 0; diff --git a/jet2.cpp b/jet2.cpp index afbc604..9bfa52c 100644 --- a/jet2.cpp +++ b/jet2.cpp @@ -33,6 +33,8 @@ int main(int argc, char *argv[]) { connect(s, (sockaddr *) &addr, sizeof(sockaddr_in)); int mode = NORMAL_MODE; + int cursor_x = 0; + int cursor_y = 0; int quit = 0; while (!quit) { @@ -47,6 +49,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < window_width * window_height; i++) { printw("%c", view[i]); } + move(cursor_y, cursor_x); int8_t mov[2]; int8_t del[1]; @@ -64,11 +67,31 @@ int main(int argc, char *argv[]) { mov[0] = OP_MOVE1; mov[1] = -1; write(s, mov, 2); + do { + if (cursor_x <= 0) { + if (cursor_y > 0) { + cursor_x = window_width - 1; + cursor_y--; + } + } else { + cursor_x--; + } + } while (view[pos(cursor_x, cursor_y)] == 0); break; case 'l': mov[0] = OP_MOVE1; mov[1] = 1; write(s, mov, 2); + do { + if (cursor_x >= window_width - 1) { + if (cursor_y < window_height - 1) { + cursor_x = 0; + cursor_y++; + } + } else { + cursor_x++; + } + } while (view[pos(cursor_x, cursor_y)] == 0); break; } } else { -- cgit v1.2.3 From 905ae13aa12abc3fbbafc646a722b2d38bbeef8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Thu, 16 Jul 2020 21:12:46 -0300 Subject: Fix client crash when cursor goes to end of file --- jet2.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jet2.cpp b/jet2.cpp index 9bfa52c..9fb4027 100644 --- a/jet2.cpp +++ b/jet2.cpp @@ -87,6 +87,8 @@ int main(int argc, char *argv[]) { if (cursor_y < window_height - 1) { cursor_x = 0; cursor_y++; + } else { + break; } } else { cursor_x++; -- cgit v1.2.3