FTXUI  2.0.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
screen_interactive.hpp
Go to the documentation of this file.
1#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
2#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
3
4#include <atomic> // for atomic
5#include <ftxui/component/receiver.hpp> // for Receiver, Sender
6#include <functional> // for function
7#include <memory> // for shared_ptr
8#include <string> // for string
9#include <thread> // for thread
10
11#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
12#include "ftxui/component/event.hpp" // for Event
13#include "ftxui/screen/screen.hpp" // for Screen
14
15namespace ftxui {
16class ComponentBase;
17struct Event;
18
19using Component = std::shared_ptr<ComponentBase>;
20
21class ScreenInteractive : public Screen {
22 public:
23 using Callback = std::function<void()>;
24
25 static ScreenInteractive FixedSize(int dimx, int dimy);
29
30 void Loop(Component);
32
33 void PostEvent(Event event);
35
36 // Decorate a function. The outputted one will execute similarly to the
37 // inputted one, but with the currently active screen terminal hooks
38 // temporarily uninstalled.
40
41 private:
42 void Install();
43 void Uninstall();
44
45 void Main(Component component);
46 ScreenInteractive* suspended_screen_ = nullptr;
47
48 void Draw(Component component);
49 void EventLoop(Component component);
50
51 enum class Dimension {
53 Fixed,
56 };
57 Dimension dimension_ = Dimension::Fixed;
58 bool use_alternative_screen_ = false;
60 int dimy,
61 Dimension dimension,
62 bool use_alternative_screen);
63
64 Sender<Event> event_sender_;
65 Receiver<Event> event_receiver_;
66
67 std::string set_cursor_position;
68 std::string reset_cursor_position;
69
70 std::atomic<bool> quit_ = false;
71 std::thread event_listener_;
72
73 int cursor_x_ = 1;
74 int cursor_y_ = 1;
75
76 bool mouse_captured = false;
77 bool previous_frame_resized_ = false;
78};
79
80} // namespace ftxui
81
82#endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */
83
84// Copyright 2020 Arthur Sonzogni. All rights reserved.
85// Use of this source code is governed by the MIT license that can be found in
86// the LICENSE file.
static ScreenInteractive TerminalOutput()
static ScreenInteractive FixedSize(int dimx, int dimy)
static ScreenInteractive FitComponent()
static ScreenInteractive Fullscreen()
std::function< void()> Callback
Callback WithRestoredIO(Callback)
Decorate a function. It executes the same way, but with the currently active screen terminal hooks te...
A rectangular grid of Pixel.
Definition screen.hpp:51
int dimy() const
Definition screen.hpp:68
int dimx() const
Definition screen.hpp:67
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::unique_ptr< ReceiverImpl< T > > Receiver
Definition receiver.hpp:45
std::unique_ptr< SenderImpl< T > > Sender
Definition receiver.hpp:44
std::shared_ptr< ComponentBase > Component
Represent an event. It can be key press event, a terminal resize, or more ...
Definition event.hpp:25