aboutsummaryrefslogtreecommitdiff
path: root/src/engine/user/input.hpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-20 13:17:16 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:56 +0200
commit78f5d8cf644383adf20933ad64c160c07c2c54fb (patch)
tree2a348d90f8f150665c379bf2f3741731999dd679 /src/engine/user/input.hpp
parentb6061eff99907495de282f611e8389e6468a1fb0 (diff)
refactor: improve input configuring structure
Diffstat (limited to 'src/engine/user/input.hpp')
-rw-r--r--src/engine/user/input.hpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp
index 3dd7fa9..d2aa447 100644
--- a/src/engine/user/input.hpp
+++ b/src/engine/user/input.hpp
@@ -1,9 +1,11 @@
#pragma once
#include "DI/auto_wirable.hpp"
+#include "interfaces/command.hpp"
#include "interfaces/input.hpp"
#include "interfaces/observable.hpp"
+#include <limits>
#include <memory>
#include <termios.h>
#include <unordered_map>
@@ -16,16 +18,21 @@ public:
void listen() const noexcept override;
- void attach(const char &event, Callback callback) noexcept override;
+ void attach(const char &key,
+ const std::shared_ptr<ICommand> &command) noexcept override;
- void notify(const char &event) const noexcept override;
+ void notify(const char &key) const noexcept override;
void enter_raw_mode() noexcept override;
void leave_raw_mode() noexcept override;
private:
- std::unordered_map<char, std::vector<Callback>> _key_observers;
+ std::array<std::vector<std::shared_ptr<ICommand>>, CHAR_MAX> _key_commands;
std::shared_ptr<termios> _original_termios = nullptr;
+
+ using _KeyCommandsSizeType = decltype(_key_commands)::size_type;
+
+ static _KeyCommandsSizeType _key_as_index(const char &key) noexcept;
};