FTXUI/include/ftxui/component/screen_interactive.hpp
ArthurSonzogni 09a1b16613 Add a Producer/Consumer system.
It allow you to create the two end of a pipe: A producer and consumer.
The producer can be moved into another thread.
Several producer can be created if necessary.

This will ease merging:
https://github.com/ArthurSonzogni/FTXUI/pull/11
2020-03-24 23:42:17 +01:00

56 lines
1.3 KiB
C++

#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
#include <atomic>
#include <condition_variable>
#include <functional>
#include <memory>
#include <mutex>
#include <queue>
#include "ftxui/component/event.hpp"
#include "ftxui/screen/screen.hpp"
#include <ftxui/component/producer_consumer.hpp>
namespace ftxui {
class Component;
class ScreenInteractive : public Screen {
public:
static ScreenInteractive FixedSize(int dimx, int dimy);
static ScreenInteractive Fullscreen();
static ScreenInteractive FitComponent();
static ScreenInteractive TerminalOutput();
~ScreenInteractive();
void Loop(Component*);
std::function<void()> ExitLoopClosure();
void PostEvent(Event event);
private:
void Draw(Component* component);
void EventLoop(Component* component);
enum class Dimension {
FitComponent,
Fixed,
Fullscreen,
TerminalOutput,
};
Dimension dimension_ = Dimension::Fixed;
ScreenInteractive(int dimx, int dimy, Dimension dimension);
Producer<Event> event_producer_;
Consumer<Event> event_consumer_;
std::string set_cursor_position;
std::string reset_cursor_position;
std::atomic<bool>quit_ = false;
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */