From dacf6e0625d10ff47d2aad0ca8d705f90f030119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Wed, 22 Jul 2020 22:52:51 -0300 Subject: Update architecture --- src/client/cursor.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/client/cursor.cpp (limited to 'src/client/cursor.cpp') diff --git a/src/client/cursor.cpp b/src/client/cursor.cpp new file mode 100644 index 0000000..226b8a5 --- /dev/null +++ b/src/client/cursor.cpp @@ -0,0 +1,46 @@ +class Cursor { + int x; + int y; + Window &w; + + public: + + Cursor(Window &w) : x(0), y(0), w(w) {} + + char element() { + return w.view[x + y * w.width]; + } + + void move_left() { + if (x == 0) { + if (y != 0) { + y--; + x = w.line_ends[y]; + } + } else { + x--; + } + } + + void move_right() { + if (element()) { + if (element() == '\n') { + x = 0; + y++; + } else { + x++; + } + } + } + + void move_up() { + } + + void move_down() { + } + + void update() { + w.set_cursor(x, y); + } +}; + -- cgit v1.2.3