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.hpp | |
parent | 70b21e90d7be4d892b7d17440d64630e7ee1a575 (diff) |
feat: add moving cursor
Diffstat (limited to 'src/engine/user/cursor.hpp')
-rw-r--r-- | src/engine/user/cursor.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp new file mode 100644 index 0000000..0317dc5 --- /dev/null +++ b/src/engine/user/cursor.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include "DI/auto_wirable.hpp" +#include "interfaces/direction.hpp" +#include "interfaces/vector2.hpp" + +#include "fmt/core.h" +#include <array> +#include <memory> +#include <unordered_map> + +constexpr std::string_view MOVE_CURSOR_UP = "{esc}[{amount}A"; +constexpr std::string_view MOVE_CURSOR_DOWN = "{esc}[{amount}B"; +constexpr std::string_view MOVE_CURSOR_LEFT = "{esc}[{amount}D"; +constexpr std::string_view MOVE_CURSOR_RIGHT = "{esc}[{amount}C"; + +constexpr fmt::string_view MOVE_CURSOR_TO = "{esc}[{row};{column}H"; + +constexpr fmt::string_view REQUEST_CURSOR_POSITION = "{esc}[6n"; + +constexpr fmt::string_view CURSOR_VISIBLE = "{esc}[?25h"; +constexpr fmt::string_view CURSOR_INVISIBLE = "{esc}[?25l"; + +class CursorController + : public AutoWirable<CursorController, CursorController, IVector2Factory> +{ +public: + explicit CursorController(IVector2Factory vector2_factory); + + template <Direction::value_type direction> + constexpr void move(const unsigned int &amount) const; + + static void move_to(const IVector2 &pos); + + static void hide(); + + static void show(); + + [[nodiscard]] std::shared_ptr<IVector2> where(); + +private: + IVector2Factory _vector2_factory; +}; + +#include "cursor.tpp" |