FTXUI  4.1.1
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#include <variant> // for variant
11
12#include "ftxui/component/animation.hpp" // for TimePoint
13#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
14#include "ftxui/component/event.hpp" // for Event
15#include "ftxui/component/task.hpp" // for Task, Closure
16#include "ftxui/screen/screen.hpp" // for Screen
17
18namespace ftxui {
19class ComponentBase;
20class Loop;
21struct Event;
22
23using Component = std::shared_ptr<ComponentBase>;
24class ScreenInteractivePrivate;
25
26class ScreenInteractive : public Screen {
27 public:
28 // Constructors:
29 static ScreenInteractive FixedSize(int dimx, int dimy);
33
34 // Return the currently active screen, nullptr if none.
35 static ScreenInteractive* Active();
36
37 // Start/Stop the main loop.
38 void Loop(Component);
39 void Exit();
41
42 // Post tasks to be executed by the loop.
43 void Post(Task task);
44 void PostEvent(Event event);
46
48
49 // Decorate a function. The outputted one will execute similarly to the
50 // inputted one, but with the currently active screen terminal hooks
51 // temporarily uninstalled.
53
54 private:
55 void ExitNow();
56
57 void Install();
58 void Uninstall();
59
60 void PreMain();
61 void PostMain();
62
63 bool HasQuitted();
64 void RunOnce(Component component);
65 void RunOnceBlocking(Component component);
66
67 void HandleTask(Component component, Task& task);
68 void Draw(Component component);
69 void ResetCursorPosition();
70
71 void Signal(int signal);
72
73 ScreenInteractive* suspended_screen_ = nullptr;
74 enum class Dimension {
76 Fixed,
79 };
80 Dimension dimension_ = Dimension::Fixed;
81 bool use_alternative_screen_ = false;
83 int dimy,
84 Dimension dimension,
85 bool use_alternative_screen);
86
87 Sender<Task> task_sender_;
88 Receiver<Task> task_receiver_;
89
90 std::string set_cursor_position;
91 std::string reset_cursor_position;
92
93 std::atomic<bool> quit_ = false;
94 std::thread event_listener_;
95 std::thread animation_listener_;
96 bool animation_requested_ = false;
97 animation::TimePoint previous_animation_time_;
98
99 int cursor_x_ = 1;
100 int cursor_y_ = 1;
101
102 bool mouse_captured = false;
103 bool previous_frame_resized_ = false;
104
105 bool frame_valid_ = false;
106
107 friend class Loop;
108
109 public:
110 class Private {
111 public:
112 static void Signal(ScreenInteractive& s, int signal) { s.Signal(signal); }
113 };
114 friend Private;
115};
116
117} // namespace ftxui
118
119#endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */
120
121// Copyright 2020 Arthur Sonzogni. All rights reserved.
122// Use of this source code is governed by the MIT license that can be found in
123// the LICENSE file.
static void Signal(ScreenInteractive &s, int signal)
static ScreenInteractive TerminalOutput()
static ScreenInteractive FixedSize(int dimx, int dimy)
static ScreenInteractive FitComponent()
static ScreenInteractive Fullscreen()
static ScreenInteractive * Active()
Closure WithRestoredIO(Closure)
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:57
int dimy() const
Definition screen.hpp:74
int dimx() const
Definition screen.hpp:73
std::chrono::time_point< Clock > TimePoint
Definition animation.hpp:20
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::variant< Event, Closure, AnimationTask > Task
Definition task.hpp:11
std::function< void()> Closure
Definition task.hpp:10
std::shared_ptr< ComponentBase > Component
Represent an event. It can be key press event, a terminal resize, or more ...
Definition event.hpp:26