Skip to content

App

#include <App.hpp>

The main application class that manages the TUI event loop and rendering.

App is the entry point for a Vextr application. It manages:

  • The root widget and widget tree

  • The event loop (input handling, rendering, layout)

  • Terminal initialization and rendering

  • Focus management

Typical usage:

auto app = std::make_unique<App>();
auto root = std::make_shared<Container>();
// ... add widgets to root
app->setRoot(root);
app->run(); // blocks until quit() is called
ReturnNameDescription
backend::RendererrendererManages rendering output to the terminal. Provides methods to draw to the screen.
std::function< bool(const core::events::Event &)>quitEventPredicate that decides whether an event should quit the app. Default: Ctrl+C.
utils::InputReaderinputReader
utils::InputParserinputParser
intescapeTimer

backend::Renderer renderer

Manages rendering output to the terminal. Provides methods to draw to the screen.


std::function< bool(const core::events::Event &)> quitEvent =
[](/api/const &e) {
if (auto *k = std::get_if<>(&e)) {
return k->key == 'c' && k->modifiers.ctrl;
}
return false;
}

Predicate that decides whether an event should quit the app. Default: Ctrl+C.


utils::InputReader inputReader

utils::InputParser inputParser

int escapeTimer = 0
ReturnNameDescription
AppCreates a new App instance and initializes the terminal.
~AppDestroys the App and restores the terminal.
voidsetRootSets the root widget of the application.
voidrunStarts the event loop and blocks until quit() is called.
voidquit inlineStops the event loop and exits run().

App()

Creates a new App instance and initializes the terminal.


~App()

Destroys the App and restores the terminal.


void setRoot(std::shared_ptr< core::Widget > root)

Sets the root widget of the application.

The root widget and its children form the widget tree that will be rendered and receive input events. This must be called before run().

  • root The root widget. Must not be null.

void run()

Starts the event loop and blocks until quit() is called.

This initializes the terminal, then repeatedly:

  • Polls for input events

  • Processes them through the widget tree

  • Measures and lays out widgets

  • Renders to the terminal


inline

inline void quit()

Stops the event loop and exits run().

Can be called from input handlers or callbacks to stop the application.

ReturnNameDescription
std::shared_ptr< core::Widget >root
backend::Terminalterminal
std::unique_ptr< backend::Buffer >buffer
core::SizecurrentSize
boolrunning
boolneedsRedraw

std::shared_ptr< core::Widget > root

backend::Terminal terminal

std::unique_ptr< backend::Buffer > buffer

core::Size currentSize = {0, 0}

bool running = false

bool needsRedraw = false
ReturnNameDescription
voidtick
voidhandleResize

void tick()

void handleResize()