Loading...
Searching...
No Matches
loop.cpp
Go to the documentation of this file.
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include "ftxui/component/loop.hpp"
#include <utility> // for move
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive, Component
namespace ftxui {
/// @brief A Loop is a wrapper around a Component and a ScreenInteractive.
/// It is used to run a Component in a terminal.
/// @ingroup component
/// @see Component, ScreenInteractive.
/// @see ScreenInteractive::Loop().
/// @see ScreenInteractive::ExitLoop().
/// @param[in] screen The screen to use.
/// @param[in] component The component to run.
// NOLINTNEXTLINE
Loop::Loop(ScreenInteractive* screen, Component component)
: screen_(screen), component_(std::move(component)) {
screen_->PreMain();
}
Loop::~Loop() {
screen_->PostMain();
}
/// @brief Whether the loop has quitted.
/// @ingroup component
bool Loop::HasQuitted() {
return screen_->HasQuitted();
}
/// @brief Execute the loop. Make the `component` to process every pending
/// tasks/events. A new frame might be drawn if the previous was invalidated.
/// Return true until the loop hasn't completed.
void Loop::RunOnce() {
screen_->RunOnce(component_);
}
/// @brief Wait for at least one event to be handled and execute
/// `Loop::RunOnce()`.
void Loop::RunOnceBlocking() {
screen_->RunOnceBlocking(component_);
}
/// Execute the loop, blocking the current thread, up until the loop has
/// quitted.
void Loop::Run() {
while (!HasQuitted()) {
RunOnceBlocking();
}
}
} // namespace ftxui
ftxui::Loop::HasQuitted
bool HasQuitted()
Whether the loop has quitted.
Definition loop.cpp:32
ftxui::Loop::~Loop
~Loop()
Definition loop.cpp:26
ftxui::Loop::Run
void Run()
Definition loop.cpp:51
ftxui::Loop::Loop
Loop(ScreenInteractive *screen, Component component)
A Loop is a wrapper around a Component and a ScreenInteractive. It is used to run a Component in a te...
Definition loop.cpp:21
ftxui::Loop::RunOnce
void RunOnce()
Execute the loop. Make the component to process every pending tasks/events. A new frame might be draw...
Definition loop.cpp:39
ftxui::Loop::RunOnceBlocking
void RunOnceBlocking()
Wait for at least one event to be handled and execute Loop::RunOnce().
Definition loop.cpp:45
ftxui::ScreenInteractive
Definition screen_interactive.hpp:30
loop.hpp
ftxui
Definition animation.hpp:10
ftxui::Make
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
ftxui::Component
std::shared_ptr< ComponentBase > Component
Definition component_base.hpp:24
screen_interactive.hpp