summaryrefslogtreecommitdiff
path: root/src/client/window.cpp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-22 22:52:51 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-22 22:52:51 -0300
commitdacf6e0625d10ff47d2aad0ca8d705f90f030119 (patch)
treebfb7f55d024c96b2390bd5f999455b2285542828 /src/client/window.cpp
parentba2c428dca0080cd79ea3e6c7d0f48764076fd2c (diff)
downloadjet-dacf6e0625d10ff47d2aad0ca8d705f90f030119.tar.gz
jet-dacf6e0625d10ff47d2aad0ca8d705f90f030119.zip
Update architecture
Diffstat (limited to 'src/client/window.cpp')
-rw-r--r--src/client/window.cpp74
1 files changed, 17 insertions, 57 deletions
diff --git a/src/client/window.cpp b/src/client/window.cpp
index 9e389fe..14128bf 100644
--- a/src/client/window.cpp
+++ b/src/client/window.cpp
@@ -1,16 +1,12 @@
#include <cursesw.h>
-class Window {
- Socket io;
- char *view;
+struct Window {
int width;
int height;
- int cursor_x;
- int cursor_y;
-
- public:
+ char *view;
+ int *line_ends;
- Window() : cursor_x(0), cursor_y(0) {
+ Window() {
initscr();
cbreak();
noecho();
@@ -20,66 +16,30 @@ class Window {
getmaxyx(stdscr, height, width);
view = new char[width * height];
- for (int i = 0; i < width * height; i++) {
- view[i] = 0;
- }
+ for (int i = 0; i < width * height; view[i++] = 0);
- io.connect();
+ line_ends = new int[height];
+ for (int i = 0; i < height; line_ends[i++] = 0);
}
~Window() {
+ delete[] view;
+ delete[] line_ends;
endwin();
}
- void redraw() {
- clear();
-
- int8_t msg[5];
- msg[0] = OP_SHOW;
- encode2(width, msg, 1);
- encode2(height, msg, 3);
- io.send(msg, 5);
- io.recv(view, width * height);
- for (int i = 0; i < width * height; i++) {
- printw("%c", view[i]);
- }
- move(cursor_y, cursor_x);
- }
-
- char pos(size_t x, size_t y) {
- return view[x + y * width];
+ int get_input() {
+ return getch();
}
- void move_left() {
- int8_t mov[2];
- if (cursor_x > 0) {
- mov[0] = OP_MOVE1;
- mov[1] = -1;
- io.send(mov, 2);
- cursor_x--;
- }
+ void set_cursor(int x, int y) {
+ move(y, x);
}
- void move_right() {
- int8_t mov[2];
- if (cursor_x < width - 1 && pos(cursor_x + 1, cursor_y) != 0) {
- mov[0] = OP_MOVE1;
- mov[1] = 1;
- io.send(mov, 2);
- cursor_x++;
+ void update() {
+ clear();
+ for (int i = 0; i < width * height; i++) {
+ printw("%c", view[i]);
}
}
-
- void delete_element() {
- int8_t del[1];
- del[0] = OP_DELETE;
- io.send(del, 1);
- }
-
- void insert_element(int input) {
- int8_t ins[2];
- ins[0] = OP_INSERT;
- ins[1] = input;
- io.send(ins, 2);
- }
};