diff options
author | HampusM <hampus@hampusmat.com> | 2022-04-24 17:13:52 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:58 +0200 |
commit | db6edcd473a684420e9a7611b24462df21165c1b (patch) | |
tree | 9646bdb4f5f6e339a0a01873b44e0b185476ce56 /src/engine/user | |
parent | b36d072ad7a7b9c6e30fcb25d6bbb001a8393468 (diff) |
style: improve function and brace styling
Diffstat (limited to 'src/engine/user')
-rw-r--r-- | src/engine/user/cursor.cpp | 29 | ||||
-rw-r--r-- | src/engine/user/cursor.hpp | 14 | ||||
-rw-r--r-- | src/engine/user/input.cpp | 8 | ||||
-rw-r--r-- | src/engine/user/input.hpp | 16 |
4 files changed, 40 insertions, 27 deletions
diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp index 2b240b9..71f02da 100644 --- a/src/engine/user/cursor.cpp +++ b/src/engine/user/cursor.cpp @@ -5,14 +5,17 @@ #include <cstdlib> #include <iostream> -CursorController::CursorController() noexcept : _position({.x = 0, .y = 0}) {} +CursorController::CursorController() noexcept : _position({ .x = 0, .y = 0 }) {} void CursorController::move(const Vector2 &direction, const uint32_t &amount) noexcept { auto direction_format = direction_format_map.at(direction); - fmt::print(fmt::runtime(direction_format.data()), fmt::arg("esc", ESC), - fmt::arg("amount", amount)); + fmt::print( + fmt::runtime(direction_format.data()), + fmt::arg("esc", ESC), + fmt::arg("amount", amount) + ); std::cout.flush(); _position = _position.to_direction(direction, static_cast<Vector2::Value>(amount)); @@ -22,8 +25,12 @@ void CursorController::move(const Vector2 &direction, const uint32_t &amount) no void CursorController::move_to(const Vector2 &position, bool silent) noexcept { - fmt::print(MOVE_CURSOR_TO, fmt::arg("esc", ESC), fmt::arg("row", position.get_y()), - fmt::arg("column", position.get_x())); + fmt::print( + MOVE_CURSOR_TO, + fmt::arg("esc", ESC), + fmt::arg("row", position.get_y()), + fmt::arg("column", position.get_x()) + ); std::cout.flush(); _position = position; @@ -66,19 +73,21 @@ void CursorController::show() noexcept std::cout.flush(); } -void CursorController::subscribe(const Event &event, - const Subscriber &subscriber) noexcept +void CursorController::subscribe( + const Event &event, + const Subscriber &subscriber +) noexcept { if (_subscribers.count(event) == 0) { - _subscribers.insert({event, std::vector<Subscriber>()}); + _subscribers.insert({ event, std::vector<Subscriber>() }); } _subscribers.at(event).push_back(subscriber); } -void CursorController::notify_subscribers(const Event &event, - const Context &context) const noexcept +void CursorController::notify_subscribers(const Event &event, const Context &context) + const noexcept { if (_subscribers.count(event) == 0) { diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp index fcdfd3b..9d614f1 100644 --- a/src/engine/user/cursor.hpp +++ b/src/engine/user/cursor.hpp @@ -23,11 +23,11 @@ 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}}; +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 ICursorController, public AutoWirable<ICursorController, CursorController> @@ -49,8 +49,8 @@ public: void subscribe(const Event &event, const Subscriber &subscriber) noexcept override; - void notify_subscribers(const Event &event, - const Context &context) const noexcept override; + void notify_subscribers(const Event &event, const Context &context) + const noexcept override; private: Vector2 _position; diff --git a/src/engine/user/input.cpp b/src/engine/user/input.cpp index 1d6bc09..d335fc9 100644 --- a/src/engine/user/input.cpp +++ b/src/engine/user/input.cpp @@ -14,15 +14,17 @@ void InputHandler::listen() const noexcept } void InputHandler::subscribe( - const Event &event, const std::shared_ptr<ISubscriber<Context>> &subscriber) noexcept + const Event &event, + const std::shared_ptr<ISubscriber<Context>> &subscriber +) noexcept { auto event_index = _event_as_index(event); _subscribers.at(event_index).push_back(subscriber); } -void InputHandler::notify_subscribers(const Event &event, - const Context &context) const noexcept +void InputHandler::notify_subscribers(const Event &event, const Context &context) + const noexcept { auto event_index = _event_as_index(event); diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp index 410f3a6..6a7bf26 100644 --- a/src/engine/user/input.hpp +++ b/src/engine/user/input.hpp @@ -17,20 +17,22 @@ public: void listen() const noexcept override; - void - subscribe(const Event &event, - const std::shared_ptr<ISubscriber<Context>> &subscriber) noexcept override; + void subscribe( + const Event &event, + const std::shared_ptr<ISubscriber<Context>> &subscriber + ) noexcept override; - void notify_subscribers(const Event &event, - const Context &context) const noexcept override; + void notify_subscribers(const Event &event, const Context &context) + const noexcept override; void enter_raw_mode() noexcept override; void leave_raw_mode() noexcept override; private: - std::array<std::vector<std::shared_ptr<ISubscriber<Context>>>, - static_cast<std::size_t>(CHAR_MAX * 2U)> + std::array< + std::vector<std::shared_ptr<ISubscriber<Context>>>, + static_cast<std::size_t>(CHAR_MAX * 2U)> _subscribers; std::shared_ptr<termios> _original_termios = nullptr; |