blob: d2aa447f4b9a5b0a97bbc395b431dea866e67dcc (
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
32
33
34
35
36
37
38
|
#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>
#include <vector>
class InputHandler : public IInputHandler, public AutoWirable<IInputHandler, InputHandler>
{
public:
InputHandler() noexcept = default;
void listen() const noexcept override;
void attach(const char &key,
const std::shared_ptr<ICommand> &command) noexcept override;
void notify(const char &key) const noexcept override;
void enter_raw_mode() noexcept override;
void leave_raw_mode() noexcept override;
private:
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;
};
|