diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-07-17 23:31:57 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-07-17 23:31:57 -0300 |
commit | e9122394f97d54a6b28b4dd52db24e22cb1ab340 (patch) | |
tree | aefb94d3c11daca71b52757a2d52a414a7a8f5ab /src/client/jetc.cpp | |
parent | d608bef678fa97b3af910fa62598c55f33650825 (diff) | |
download | jet-e9122394f97d54a6b28b4dd52db24e22cb1ab340.tar.gz jet-e9122394f97d54a6b28b4dd52db24e22cb1ab340.zip |
Move main files into subdirectories
Diffstat (limited to 'src/client/jetc.cpp')
-rw-r--r-- | src/client/jetc.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/client/jetc.cpp b/src/client/jetc.cpp new file mode 100644 index 0000000..8d31d72 --- /dev/null +++ b/src/client/jetc.cpp @@ -0,0 +1,98 @@ +#include <stdio.h> +#include <string.h> +#include <cursesw.h> + +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/ip.h> +#include <arpa/inet.h> +#include <unistd.h> + +#include <common/ipc.cpp> +#include <client/window.cpp> +#include <client/cursor.cpp> + +#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(); + + 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) { + case '': + quit = 1; + break; + case 'i': + mode = INSERT_MODE; + break; + case 'h': + mov[0] = OP_MOVE1; + mov[1] = -1; + write(s, mov, 2); + cursor.move_left(); + break; + case 'l': + mov[0] = OP_MOVE1; + mov[1] = 1; + write(s, mov, 2); + cursor.move_right(); + break; + } + } else { + switch (input) { + case '': + mode = NORMAL_MODE; + break; + case KEY_BACKSPACE: + del[0] = OP_DELETE; + write(s, del, 1); + break; + default: + ins[0] = OP_INSERT; + ins[1] = input; + write(s, ins, 2); + } + } + } + + close(s); + + endwin(); + return 0; +} |