aboutsummaryrefslogtreecommitdiff
path: root/src/engine/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/user')
-rw-r--r--src/engine/user/cursor.cpp9
-rw-r--r--src/engine/user/cursor.hpp15
-rw-r--r--src/engine/user/cursor.tpp31
3 files changed, 18 insertions, 37 deletions
diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp
index 44e24dc..391a91a 100644
--- a/src/engine/user/cursor.cpp
+++ b/src/engine/user/cursor.cpp
@@ -5,6 +5,15 @@
#include <cstdlib>
#include <iostream>
+void CursorController::move(const Vector2 &direction, const uint32_t &amount)
+{
+ auto format = direction_format_map.at(direction);
+
+ fmt::print(fmt::runtime(format.data()), fmt::arg("esc", ESC),
+ fmt::arg("amount", amount));
+ std::cout.flush();
+}
+
void CursorController::move_to(const Vector2 &pos)
{
fmt::print(MOVE_CURSOR_TO, fmt::arg("esc", ESC), fmt::arg("row", pos.get_y()),
diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp
index 70a2bf2..84117c1 100644
--- a/src/engine/user/cursor.hpp
+++ b/src/engine/user/cursor.hpp
@@ -1,13 +1,13 @@
#pragma once
#include "DI/auto_wirable.hpp"
-#include "interfaces/direction.hpp"
#include "engine/data/vector2.hpp"
-#include "fmt/core.h"
#include <array>
+#include <fmt/core.h>
#include <memory>
+#include <string_view>
#include <unordered_map>
constexpr std::string_view MOVE_CURSOR_UP = "{esc}[{amount}A";
@@ -22,13 +22,18 @@ 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";
+const std::unordered_map<Vector2, std::string_view, Vector2Hasher> direction_format_map =
+ {{Vector2::up(), MOVE_CURSOR_UP},
+ {Vector2::down(), MOVE_CURSOR_DOWN},
+ {Vector2::left(), MOVE_CURSOR_LEFT},
+ {Vector2::right(), MOVE_CURSOR_RIGHT}};
+
class CursorController : public AutoWirable<CursorController, CursorController>
{
public:
CursorController() = default;
- template <Direction::value_type direction>
- constexpr void move(const uint32_t &amount) const;
+ static void move(const Vector2 &direction, const uint32_t &amount);
static void move_to(const Vector2 &pos);
@@ -38,5 +43,3 @@ public:
[[nodiscard]] static Vector2 where();
};
-
-#include "cursor.tpp"
diff --git a/src/engine/user/cursor.tpp b/src/engine/user/cursor.tpp
deleted file mode 100644
index 0743ae8..0000000
--- a/src/engine/user/cursor.tpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#pragma once
-
-#include "cursor.hpp"
-
-#include "engine/escape.hpp"
-
-#include <iostream>
-
-constexpr auto get_direction_format_map()
-{
- std::array<std::string_view, 4> direction_format_map;
-
- direction_format_map[Direction::UP] = MOVE_CURSOR_UP;
- direction_format_map[Direction::DOWN] = MOVE_CURSOR_DOWN;
- direction_format_map[Direction::LEFT] = MOVE_CURSOR_LEFT;
- direction_format_map[Direction::RIGHT] = MOVE_CURSOR_RIGHT;
-
- return direction_format_map;
-}
-
-template <Direction::value_type direction>
-constexpr void CursorController::move(const uint32_t &amount) const
-{
- constexpr auto direction_format_map = get_direction_format_map();
-
- constexpr auto format = direction_format_map[direction];
-
- fmt::vprint(format,
- fmt::make_format_args(fmt::arg("esc", ESC), fmt::arg("amount", amount)));
- std::cout.flush();
-}