AppCUI::Application

namespace Application

Application lifetime: initialization (Init, InitializationData), the event loop (Run), desktop windows (AddWindow, ArrangeWindows), menus, themes, settings (<executable>.ini) and custom frontends.

Classes

  • CommandBar

  • Config

  • CustomFrontendInterface - A frontend implemented by the application instead of a real terminal (headless / remote / recording screens).

  • FrontendEvent - An input event produced by a custom frontend (see CustomFrontendInterface::WaitForEvent).

  • InitializationData - Every parameter of Application::Init.

  • ThemeInfo - A theme known to the theme registry (see Application::EnumerateThemes).

Enumerations

enum class AppCUI::Application::InitializationFlags : uint32

Options of Application::Init (they can be combined with |).

Values:

enumerator None = 0
enumerator CommandBar = 0x0001

a command bar (shortcut keys) is shown on the last line

enumerator Menu = 0x0002

a menu bar is shown on the first line (see Application::AddMenu)

enumerator Maximized = 0x0004

the terminal window is maximized (frontend dependent)

enumerator Fullscreen = 0x0008

the terminal window is full screen (frontend dependent)

enumerator FixedSize = 0x0010

the terminal window can not be resized (frontend dependent)

enumerator LoadSettingsFile = 0x0020

loads <executable>.ini; its [AppCUI] section configures the application

enumerator AutoHotKeyForWindow = 0x0040

every new window receives a free Alt+1 .. Alt+9 hot key

enumerator EnableFPSMode = 0x0080

Control::OnFrameUpdate is called ~30 times per second.

enumerator SingleWindowApp = 0x0100

single application mode: start with Application::RunSingleApp

enumerator DisableAutoCloseDesktop = 0x0200

the application keeps running after its last window was closed

enum class AppCUI::Application::CharacterSize : uint32

Size of a character (SDL and Windows console frontends).

Values:

enumerator Default = 0
enumerator Tiny
enumerator Small
enumerator Normal
enumerator Large
enumerator Huge
enum class AppCUI::Application::FrontendType : uint32

The frontend (terminal implementation) that displays the application.

Values:

enumerator Default = 0
enumerator SDL = 1
enumerator Terminal = 2
enumerator WindowsConsole = 3
enumerator Tests = 4
enumerator Custom = 5
enumerator Browser = 6

HTML5 canvas inside a web page (wasm32-emscripten builds only).

enum class AppCUI::Application::ThemeType : uint32

Built-in color themes (defined in code: they need no file and work on every frontend).

New themes are only appended, so the value of an existing theme never changes. See EnumerateThemes / GetThemeName.

Values:

enumerator Default = 0
enumerator Dark = 1
enumerator Light = 2
enumerator HighContrast = 3

accessibility: strong foreground / background separation

enumerator Midnight = 4

dark blue / black

enumerator Ocean = 5

teal / cyan

enumerator Forest = 6

green / olive

enumerator RetroGreen = 7

green on black (monochrome terminal)

enumerator Amethyst = 8

dark purple: black windows in purple surroundings, made for reading code for hours

enum class AppCUI::Application::ThemeSource : uint32

Where a theme listed by Application::EnumerateThemes comes from.

Values:

enumerator BuiltIn = 0

one of the ThemeType themes

enumerator File = 1

a <Name>.theme file from the themes folder

enumerator Settings = 2

an [AppCUI.Theme.<Name>] section of the settings file (edited themes, browser frontend)

enum class AppCUI::Application::SpecialCharacterSetType : uint32

Characters used to draw lines, borders, arrows and other special characters.

Values:

enumerator Auto = 0
enumerator Unicode = 1
enumerator LinuxTerminal = 2
enumerator Ascii = 3
enum class AppCUI::Application::FrontendEventType : uint32

Type of a FrontendEvent produced by a CustomFrontendInterface.

Values:

enumerator None = 0
enumerator KeyPressed
enumerator ShiftStateChanged
enumerator MouseDown
enumerator MouseUp
enumerator MouseMove
enumerator MouseWheel
enumerator Resized
enumerator Closed
enumerator RedrawRequested
enum class AppCUI::Application::ArrangeWindowsMethod

How Application::ArrangeWindows places the desktop windows.

Values:

enumerator MaximizedAll
enumerator Cascade
enumerator Vertical
enumerator Horizontal
enumerator Grid

Functions

Config *AppCUI::Application::GetAppConfig()

Colors of the current theme (nullptr if the application is not initialized).

Utils::IniObject *AppCUI::Application::GetAppSettings()

Settings read from <executable>.ini (InitializationFlags::LoadSettingsFile); nullptr if the application is not initialized.

bool AppCUI::Application::SaveAppSettings()

Writes the settings (GetAppSettings) back to GetAppSettingsFile().

void AppCUI::Application::UpdateAppCUISettings(Utils::IniObject &ini, bool clearExistingSettings = false)

Adds the default [AppCUI] keys that are missing from ini (rewrites all of them when clearExistingSettings is true).

bool AppCUI::Application::UpdateAppCUISettings(bool clearExistingSettings = false)

Same as above, applied to the settings of the running application.

std::filesystem::path AppCUI::Application::GetAppSettingsFile()

Path of the settings file: the path of the executable with the .ini extension.

const Input::ModifierMap &AppCUI::Application::GetModifierMap()

Keyboard modifier profile ([AppCUI] Keyboard.Ctrl / Keyboard.Alt).

void AppCUI::Application::SetModifierMap(const Input::ModifierMap &map)

Applies a keyboard modifier profile immediately and updates the in-memory settings (call SaveAppSettings to persist it).

bool AppCUI::Application::Init(Application::InitializationFlags flags = Application::InitializationFlags::None)

Initializes AppCUI with the default parameters and the given flags. Returns false on failure.

bool AppCUI::Application::Init(InitializationData &initData)

Initializes AppCUI with the parameters described by initData (the settings file, if loaded, may change them).

bool AppCUI::Application::InitForTests(uint32 width, uint32 height, Application::InitializationFlags flags = Application::InitializationFlags::None, bool asciiMode = false)

Initializes AppCUI on the in-memory test frontend (FrontendType::Tests); see RunTestScript.

bool AppCUI::Application::Run()

Runs the event loop until Close() is called (or, by default, until the last window is closed), then un-initializes AppCUI.

bool AppCUI::Application::RunTestScript(std::string_view script)

Runs a test script (key presses, mouse events, screen hash checks) on an application started with InitForTests.

Returns false if a check of the script failed.

bool AppCUI::Application::RunSingleApp(unique_ptr<Controls::SingleApp> singleApp)

Runs an application initialized with InitializationFlags::SingleWindowApp: singleApp replaces the desktop.

Controls::ItemHandle AppCUI::Application::AddWindow(unique_ptr<Controls::Window> wnd, Controls::ItemHandle referal = Controls::InvalidItemHandle, const ConstString& = "")

Adds a top level window to the desktop.

referal is the window that opened it (the windows manager shows the windows as a tree) and the last parameter describes how it was created. Returns the handle of the new window.

Controls::ItemHandle AppCUI::Application::AddWindow(unique_ptr<Controls::Window> wnd, Controls::Window *referalWindow, const ConstString& = "")

Adds a top level window opened from referalWindow.

Controls::ItemHandle AppCUI::Application::AddWindow(unique_ptr<Controls::Window> wnd, Utils::Reference<Controls::Window> referalWindow, const ConstString& = "")

Adds a top level window opened from referalWindow.

Controls::Menu *AppCUI::Application::AddMenu(const ConstString &name)

Adds a menu to the menu bar (requires InitializationFlags::Menu). Returns nullptr on failure.

bool AppCUI::Application::GetApplicationSize(Graphics::Size &size)

Size of the whole application (terminal) in characters.

bool AppCUI::Application::GetDesktopSize(Graphics::Size &size)

Size of the desktop client area (without the menu bar and the command bar).

Utils::Reference<Controls::Window> AppCUI::Application::GetCurrentWindow()

The focused desktop window (or nullptr).

void AppCUI::Application::ArrangeWindows(ArrangeWindowsMethod method)

Re-arranges every desktop window.

void AppCUI::Application::RaiseEvent(Utils::Reference<Controls::Control> control, Utils::Reference<Controls::Control> sourceControl, Controls::Event eventType, int controlID)

Sends an event to control as if sourceControl had raised it (only valid after Init).

Utils::Reference<Controls::Desktop> AppCUI::Application::GetDesktop()

The desktop (only valid after Init).

void AppCUI::Application::Close()

Stops the event loop (the application closes).

void AppCUI::Application::SetTheme(ThemeType themeType)

Switches to a built-in theme.

The colors registered with Dialogs::ThemeEditor::RegisterCustomColors return to their registered values and every Dialogs::OnThemeChangedInterface listener is notified.

bool AppCUI::Application::SetTheme(std::string_view themeName)

Switches to a theme by name: a built-in theme (see GetThemeType; a <Name>.theme file of the themes folder, if any, is applied over it), else an [AppCUI.Theme.NAME] section of the settings file (NAME = themeName), else <name>.theme from the themes folder (applied over ThemeType::Default).

Listeners are notified. Returns false (and keeps the current theme) if the theme can not be found or loaded.

std::string AppCUI::Application::GetCurrentThemeName()

Name of the current theme (see ThemeInfo::Name); empty if the colors were edited in the theme editor and not saved under a name.

std::string_view AppCUI::Application::GetThemeName(ThemeType themeType)

Theme registry: the canonical name of a built-in theme (e.g. “HighContrast”); empty for an invalid value.

std::string_view AppCUI::Application::GetThemeDisplayName(ThemeType themeType)

Theme registry: the name of a built-in theme shown to the user (e.g. “High Contrast”).

std::optional<ThemeType> AppCUI::Application::GetThemeType(std::string_view themeName)

Theme registry: the built-in theme called themeName.

Case-insensitive; spaces, ‘-’ and ‘_’ are ignored (so “High Contrast”, “high-contrast” and “HIGHCONTRAST” all match). std::nullopt if themeName is not built-in.

bool AppCUI::Application::IsBuiltInTheme(std::string_view themeName)

Theme registry: true if themeName names a built-in theme (see GetThemeType).

std::vector<ThemeInfo> AppCUI::Application::EnumerateThemes()

Theme registry: every built-in theme (in ThemeType order), then the [AppCUI.Theme.NAME] sections of the settings file, then the *.theme files of the themes folder.

A name is listed once (case-insensitive; the first source wins, the way SetTheme resolves it). Without an initialized application, only the built-in themes are listed.

bool AppCUI::Application::SaveThemeToSettings(std::string_view themeName)

Writes [AppCUI] Theme=<themeName> to the settings (GetAppSettings) and saves them to GetAppSettingsFile(), so that the next start uses this theme (with InitializationFlags::LoadSettingsFile).

Built-in names are written in their canonical form. Returns false if the name is empty or the settings could not be saved.

bool AppCUI::Application::UsesSettingsFile()

True if the application uses a settings file (InitializationFlags::LoadSettingsFile): the theme dialogs only offer to keep a theme after a restart in that case.

bool AppCUI::Application::SetSpecialCharacterSet(SpecialCharacterSetType characterSetType)

Changes the characters used to draw lines, borders and other special characters.

Utils::PropertiesInterface *AppCUI::Application::GetAppPropertiesObject()

AppCUI settings exposed as properties (for a PropertyList).