From 8693eef8febde4df90b7fbd1fb9ac813b132fa50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 20 Jul 2020 01:50:14 -0300 Subject: Wrap external functionality into classes --- src/client/jetc.cpp | 59 ++++++----------------------------------------------- 1 file changed, 6 insertions(+), 53 deletions(-) (limited to 'src/client/jetc.cpp') diff --git a/src/client/jetc.cpp b/src/client/jetc.cpp index 8d31d72..2dd6074 100644 --- a/src/client/jetc.cpp +++ b/src/client/jetc.cpp @@ -1,57 +1,22 @@ #include #include -#include - -#include -#include -#include -#include -#include #include +#include #include -#include #define NORMAL_MODE 0 #define INSERT_MODE 1 -#define PORT 6969 int main(int argc, char *argv[]) { - initscr(); - cbreak(); - noecho(); - intrflush(stdscr, FALSE); - keypad(stdscr, TRUE); - Window window; - getmaxyx(stdscr, window.height, window.width); - window.init(); - - int s = socket(AF_INET, SOCK_STREAM, 0); - sockaddr_in addr = { AF_INET, htons(PORT), htonl(INADDR_LOOPBACK) }; - connect(s, (sockaddr *) &addr, sizeof(sockaddr_in)); int mode = NORMAL_MODE; - Cursor cursor = { 0, 0, &window }; int quit = 0; while (!quit) { - clear(); + window.redraw(); - int8_t msg[5]; - msg[0] = OP_SHOW; - encode2(window.width, msg, 1); - encode2(window.height, msg, 3); - write(s, msg, 5); - read(s, window.view, window.width * window.height); - for (int i = 0; i < window.width * window.height; i++) { - printw("%c", window.view[i]); - } - move(cursor.y, cursor.x); - - int8_t mov[2]; - int8_t del[1]; - int8_t ins[2]; int input = getch(); if (mode == NORMAL_MODE) { switch (input) { @@ -62,16 +27,10 @@ int main(int argc, char *argv[]) { mode = INSERT_MODE; break; case 'h': - mov[0] = OP_MOVE1; - mov[1] = -1; - write(s, mov, 2); - cursor.move_left(); + window.move_left(); break; case 'l': - mov[0] = OP_MOVE1; - mov[1] = 1; - write(s, mov, 2); - cursor.move_right(); + window.move_right(); break; } } else { @@ -80,19 +39,13 @@ int main(int argc, char *argv[]) { mode = NORMAL_MODE; break; case KEY_BACKSPACE: - del[0] = OP_DELETE; - write(s, del, 1); + window.delete_element(); break; default: - ins[0] = OP_INSERT; - ins[1] = input; - write(s, ins, 2); + window.insert_element(input); } } } - close(s); - - endwin(); return 0; } -- cgit v1.2.3