Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
Portals: short library guide

Русская версия · Task guides · Documentation contents · Glossary

Widget gallery — previews, examples and control guides. Portals is a C++23 terminal UI library under development. The declarative ui API is the primary way to build an interface. This page is the short reading guide; the documentation contents contains the complete topic list and API reading paths.

These Markdown guides describe the current source branch. The published HTML help follows the latest stable release; PR checks also provide an HTML preview artifact.

The first application tutorial develops a quick-note form in four steps, from a runnable editor to a styled form with save and clear actions.

The declarative API

<portals/ui.hpp> provides scenes, recipes and event handlers. <portals/ui_style.hpp> adds the style operations used in this example.

The example describes a control tree and attaches style and event handlers with UI stages, which represent operations after each |. Here, ui::vbox(...) creates a recipe: a description of the controls to construct. ui::scene(...) stores that recipe in a scene, which manages preparation and running. The button appends text to the editor, and F10 requests an orderly exit.

#include <portals/ui.hpp>
#include <portals/ui_style.hpp>
int main() {
using namespace portals;
auto scene = ui::scene(ui::vbox(
ui::label("Greeting"),
ui::lineEdit(message, ""),
ui::button(add, "Add Hello")));
return scene
| ui::style("Button { bold: true; }")
| ui::onClick(add,
[message] {
message.text() += "Hello!";
})
| ui::onKey("F10", ui::quit)
| ui::runApp();
}
Typed Widget observation; explicit composite specializations reuse their existing weak facades.
Definition ui_ref.hpp:761
TextProperty text(TextResolver resolver={}, std::source_location origin=std::source_location::current()) const
Definition ui_ref.hpp:1968
Public Portals API.
Definition action.hpp:8

The runner attempts terminal cleanup and reports failures. This compact form constructs the recipe before runApp; use the factory-based overload when construction also needs its checked error boundary. The exit command resolves the active scene inside a callback entered by the scene. An explicit SceneRef remains available when an action must target a named scene. Declarative composition explains callbacks, setup errors and the lower-level typed run() result.

Connecting the library to an application

For a local application, the complete example above can be saved as main.cpp in a directory named my-app; the following configuration belongs in CMakeLists.txt in the same directory:

cmake_minimum_required(VERSION 3.24)
project(MyApplication LANGUAGES CXX)
include(FetchContent)
FetchContent_Declare(portals
GIT_REPOSITORY https://github.com/ttldtor/portals.git
GIT_TAG 7f09c7db9547c34c547b05e4fbf18d5c9f492ee5
)
FetchContent_MakeAvailable(portals)
add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE portals::core)

From my-app, these commands configure the build, download the selected Portals revision and build the my_app executable:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build --target my_app
./build/my_app

On Windows, the build environment is an x64 Developer PowerShell for Visual Studio. On Linux, a compatible C++ compiler and standard library are required. The build uses Git, CMake 3.24+, Ninja and a toolchain supporting C99 and C++23, including the C++ library headers <expected> and <format>.

When my_app runs in a terminal, Add Hello appends text and F10 exits. On Windows the executable is build/my_app.exe; on Linux it is build/my_app. The commands above use the Ninja single-configuration generator.

GIT_TAG fixes the source revision for this example. When choosing a newer Portals version, this value can be updated. FetchContent integration is described in the CMake documentation.

Use local sources or an installed SDK

When Portals sources are already in a portals subdirectory of the project, include(FetchContent) and both FetchContent_* calls can be replaced with add_subdirectory(portals). This uses the local sources without a download.

For an installed SDK, the same lines can be replaced with find_package(Portals CONFIG REQUIRED); its installation prefix goes in CMAKE_PREFIX_PATH during configuration. Every option uses target_link_libraries(my_app PRIVATE portals::core). See package setup for installation and toolchain compatibility.

What is available

  • Forms: Label, Button, CheckBox, LineEdit, Row/Column, Grid/Overlay and observing references.
  • Data: immutable models, virtual lists/tables, scrolling and charts.
  • Styles: themes, style layers and compile-time/runtime PSS.
  • Async: optional, bounded UI coroutines on the existing Scheduler.
  • Input: shortcut strings, alternatives, sequences and explicit phase selectors. Native delivery depends on the backend; Kitty negotiation and standalone modifier keys are not implemented in this version.
  • Errors: live onError reactions and a separate final report after cleanup; applications can present explicit notifications, including persistent messages and optional indicators. Automatic error popups and a diagnostic journal are application policy.

These APIs are evolving. Limitations lists qualified platforms and the exact runtime boundaries.

Continue reading

Runnable examples link to guides with complete source programs. Release notes record changes by version.

Dependencies and licenses are listed separately.

Fine scene settings contains expandable examples of ownership budgets and input settings.