aboutsummaryrefslogtreecommitdiff
path: root/src/engine/user/input.hpp
blob: 3dd7fa92fe24d0c5ad212066a8e8fb3127ee4e9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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() noexcept = default;

	void listen() const noexcept override;

	void attach(const char &event, Callback callback) noexcept override;

	void notify(const char &event) 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::shared_ptr<termios> _original_termios = nullptr;
};