FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
loop.hpp
Go to the documentation of this file.
1// Copyright 2022 Arthur Sonzogni. All rights reserved.
2// El uso de este código fuente se rige por la licencia MIT que se puede encontrar en
3// el archivo LICENSE.
4#ifndef FTXUI_COMPONENT_LOOP_HPP
5#define FTXUI_COMPONENT_LOOP_HPP
6
7#include <memory> // for shared_ptr
8
9#include "ftxui/component/component_base.hpp" // for ComponentBase
10
11namespace ftxui {
12class ComponentBase;
13
14using Component = std::shared_ptr<ComponentBase>;
15class ScreenInteractive;
16
17/// @brief Loop es una clase que gestiona el bucle de eventos de un componente.
18///
19/// Es responsable de ejecutar el componente, manejar los eventos y
20/// actualizar la pantalla.
21///
22/// La clase Loop está diseñada para ser utilizada con un objeto ScreenInteractive,
23/// que representa la pantalla del terminal.
24///
25/// **Ejemplo**
26/// ```cpp
27/// #include <ftxui/component/component.hpp>
28/// #include <ftxui/component/screen_interactive.hpp>
29/// #include <ftxui/component/loop.hpp>
30///
31/// int main() {
32/// auto screen = ftxui::ScreenInteractive::TerminalOutput();
33/// auto component = ftxui::Button("Click me", [] { ... });
34///
35/// ftxui::Loop loop(screen.get(), component);
36///
37/// // O
38/// loop.Run(); // Bloquea hasta que el componente se cierra.
39///
40/// // O
41/// loop.RunOnce(); // No bloqueante, regresa inmediatamente.
42///
43/// // O
44/// loop.RunOnceBlocking(); // Bloquea hasta manejar un evento.
45///
46/// // O en un bucle:
47/// while (!loop.HasQuitted()) {
48/// loop.RunOnce();
49///
50/// // Haz otra cosa como ejecutar una función de bucle de otra biblioteca.
51/// }
52/// }
53/// ```
54///
55/// @ingroup component
56class Loop {
57 public:
59 ~Loop();
60
61 bool HasQuitted();
62 void RunOnce();
63 void RunOnceBlocking();
64 void Run();
65
66 // Esta clase no es copiable/movible.
67 Loop(const Loop&) = default;
68 Loop(Loop&&) = delete;
69 Loop& operator=(Loop&&) = delete;
70 Loop(const ScreenInteractive&) = delete;
71 Loop& operator=(const Loop&) = delete;
72
73 private:
74 ScreenInteractive* screen_;
75 Component component_;
76};
77
78} // namespace ftxui
79
80#endif // FTXUI_COMPONENT_LOOP_HPP
auto screen
bool HasQuitted()
Indica si el bucle ha terminado.
Definition loop.cpp:30
Loop(const ScreenInteractive &)=delete
void Run()
Definition loop.cpp:49
Loop(ScreenInteractive *screen, Component component)
Un Loop es un envoltorio alrededor de un Component y un ScreenInteractive. Se utiliza para ejecutar u...
Definition loop.cpp:20
Loop & operator=(const Loop &)=delete
void RunOnce()
Ejecuta el bucle una vez. Hace que el component procese todas las tareas/eventos pendientes....
Definition loop.cpp:37
Loop(const Loop &)=default
Loop & operator=(Loop &&)=delete
Loop(Loop &&)=delete
void RunOnceBlocking()
Espera a que se maneje al menos un evento y ejecuta Loop::RunOnce().
Definition loop.cpp:43
Loop es una clase que gestiona el bucle de eventos de un componente.
Definition loop.hpp:56
ScreenInteractive es una Screen que puede manejar eventos, ejecutar un bucle principal y administrar ...
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:10
std::shared_ptr< ComponentBase > Component