FTXUI  3.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#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 Closure, Task
16#include "ftxui/screen/screen.hpp" // for Screen
17
18namespace ftxui {
19class ComponentBase;
20struct Event;
21
22using Component = std::shared_ptr<ComponentBase>;
23class ScreenInteractivePrivate;
24
25class ScreenInteractive : public Screen {
26 public:
27 // Constructors:
28 static ScreenInteractive FixedSize(int dimx, int dimy);
32
33 // Return the currently active screen, nullptr if none.
34 static ScreenInteractive* Active();
35
36 void Loop(Component);
38
39 void Post(Task task);
40 void PostEvent(Event event);
42
44
45 // Decorate a function. The outputted one will execute similarly to the
46 // inputted one, but with the currently active screen terminal hooks
47 // temporarily uninstalled.
49
50 private:
51 void Install();
52 void Uninstall();
53
54 void Main(Component component);
55
56 void Draw(Component component);
57 void SigStop();
58
59 ScreenInteractive* suspended_screen_ = nullptr;
60 enum class Dimension {
62 Fixed,
65 };
66 Dimension dimension_ = Dimension::Fixed;
67 bool use_alternative_screen_ = false;
69 int dimy,
70 Dimension dimension,
71 bool use_alternative_screen);
72
73 Sender<Task> task_sender_;
74 Receiver<Task> task_receiver_;
75
76 std::string set_cursor_position;
77 std::string reset_cursor_position;
78
79 std::atomic<bool> quit_ = false;
80 std::thread event_listener_;
81 std::thread animation_listener_;
82 bool animation_requested_ = false;
83 animation::TimePoint previous_animation_time;
84
85 int cursor_x_ = 1;
86 int cursor_y_ = 1;
87
88 bool mouse_captured = false;
89 bool previous_frame_resized_ = false;
90
91 public:
92 class Private {
93 public:
94 static void SigStop(ScreenInteractive& s) { return s.SigStop(); }
95 };
96 friend Private;
97};
98
99} // namespace ftxui
100
101#endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */
102
103// Copyright 2020 Arthur Sonzogni. All rights reserved.
104// Use of this source code is governed by the MIT license that can be found in
105// the LICENSE file.
static void SigStop(ScreenInteractive &s)
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:53
int dimy() const
Definition screen.hpp:70
int dimx() const
Definition screen.hpp:69
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