diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-03 19:41:23 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:54 +0200 |
commit | 93123e97251fc791c1cac193d675cce9a1ac2de6 (patch) | |
tree | 4486453695d6f715e767bd91bcee89c92f54f7ba /src/engine/user/cursor.cpp | |
parent | 70b21e90d7be4d892b7d17440d64630e7ee1a575 (diff) |
feat: add moving cursor
Diffstat (limited to 'src/engine/user/cursor.cpp')
-rw-r--r-- | src/engine/user/cursor.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp new file mode 100644 index 0000000..9d6e28c --- /dev/null +++ b/src/engine/user/cursor.cpp @@ -0,0 +1,43 @@ +#include "cursor.hpp" + +#include "engine/escape.hpp" + +#include <cstdlib> +#include <iostream> + +CursorController::CursorController(IVector2Factory vector2_factory) + : _vector2_factory(vector2_factory) +{ +} + +void CursorController::move_to(const IVector2 &pos) +{ + fmt::print(MOVE_CURSOR_TO, fmt::arg("esc", ESC), fmt::arg("row", pos.y()), + fmt::arg("column", pos.x())); + std::cout.flush(); +} + +std::shared_ptr<IVector2> CursorController::where() +{ + fmt::print(REQUEST_CURSOR_POSITION, fmt::arg("esc", ESC)); + std::cout.flush(); + + IVector2Options vector2_options = {}; + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + scanf("\033[%u;%uR", &vector2_options.y, &vector2_options.x); + + return _vector2_factory(vector2_options); +} + +void CursorController::hide() +{ + fmt::print(CURSOR_INVISIBLE, fmt::arg("esc", ESC)); + std::cout.flush(); +} + +void CursorController::show() +{ + fmt::print(CURSOR_VISIBLE, fmt::arg("esc", ESC)); + std::cout.flush(); +} |