aboutsummaryrefslogtreecommitdiff
path: root/src/engine/user/input.hpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-02-28 21:30:30 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:54 +0200
commitede689d23e57c9b701ab19aa9112a0b2368865c9 (patch)
treee8c7afc7b2e5caf43b1b0c52356c0596021f25cb /src/engine/user/input.hpp
parentf0883534b3303cf2b74f3ab51efe16615d2561a9 (diff)
feat: add input handler & quitting with 'q'
Diffstat (limited to 'src/engine/user/input.hpp')
-rw-r--r--src/engine/user/input.hpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp
new file mode 100644
index 0000000..f48ab86
--- /dev/null
+++ b/src/engine/user/input.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "DI/auto_wirable.hpp"
+#include "interfaces/input.hpp"
+#include "interfaces/observable.hpp"
+
+#include <memory>
+#include <termios.h>
+#include <unordered_map>
+#include <vector>
+
+class InputHandler : public IInputHandler, public AutoWirable<IInputHandler, InputHandler>
+{
+public:
+ InputHandler() = default;
+
+ void listen() const override;
+
+ void attach(const char &event, Callback callback) override;
+
+ void notify(const char &event) const override;
+
+ void enter_raw_mode() override;
+
+ void leave_raw_mode() override;
+
+private:
+ std::unordered_map<char, std::vector<Callback>> _key_observers;
+
+ std::shared_ptr<termios> _original_termios = nullptr;
+};