From ede689d23e57c9b701ab19aa9112a0b2368865c9 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 28 Feb 2022 21:30:30 +0100 Subject: feat: add input handler & quitting with 'q' --- src/interfaces/input.hpp | 17 +++++++++++++++++ src/interfaces/observable.hpp | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/interfaces/input.hpp create mode 100644 src/interfaces/observable.hpp (limited to 'src/interfaces') diff --git a/src/interfaces/input.hpp b/src/interfaces/input.hpp new file mode 100644 index 0000000..956ec4f --- /dev/null +++ b/src/interfaces/input.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "interfaces/observable.hpp" + +class IInputHandler : public IObservable +{ +public: + void listen() const override = 0; + + void attach(const char &event, Callback callback) override = 0; + + void notify(const char &event) const override = 0; + + virtual void enter_raw_mode() = 0; + + virtual void leave_raw_mode() = 0; +}; diff --git a/src/interfaces/observable.hpp b/src/interfaces/observable.hpp new file mode 100644 index 0000000..ca8ffda --- /dev/null +++ b/src/interfaces/observable.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +using Callback = std::function; + +template +class IObservable +{ +public: + virtual void listen() const = 0; + + virtual void attach(const Event &event, Callback callback) = 0; + + virtual void notify(const Event &event) const = 0; +}; -- cgit v1.2.3-18-g5258