Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Windows VT (Virtual Terminal)

This backend is based on both Windows API and VT100 escape sequences.

For clipboard based operations, it relies on the following APIs:

  • OpenClipboard
  • EmptyClipboard
  • CloseClipboard
  • SetClipboardData
  • GetClipboardData
  • IsClipboardFormatAvailable

Input (mouse / keyboard / console resize) is handled by the following APIs:

APITask(s)
GetStdHandle(...)To gain access to stdin and stdout
GetConsoleScreenBufferInfo(...)To get information about console size and position
GetConsoleMode(...)To get information about the current mode of the console
ReadConsoleInputW(...)To read input events (keys, mouse, resizing, console closing)
SetConsoleTitleW(...)To set the title (caption) of the console
SetConsoleScreenBufferSize(...)To resize the console to a specific width and height

The output is done via VT100 escape sequences (please refer to Wikipedia for more information). This backend supports true colors (24 bits per pixel) and wide characters (2 bytes per character) but it depends on the Windows version to support them.

Palette

Windows VT uses the same console object as Windows Console, so .palette(...) still updates the console color table through SetConsoleScreenBufferInfoEx. The general rules for the two builder methods are in Palette.

PaletteConsole color table
Palette::TerminalLeft unchanged. This is the default.
Palette::BuiltInReplaced with the standard AppCUI colors.
Palette::CustomReplaced with the RGB values from the ColorPalette.

.palette_as_rgb(...) chooses how those colors are painted with ANSI sequences:

  • false (the default). Characters use the 16 color indexes. BuiltIn and Custom are also loaded into those indexes with an OSC 4 sequence.
  • true. Each character is painted with a 24-bit RGB sequence (38;2 / 48;2) taken from the palette. This requires Palette::BuiltIn or Palette::Custom.

When the application ends, Windows VT does not restore the console color table with an ANSI sequence. The table saved at startup is written back with SetConsoleScreenBufferInfoEx, the same call Windows Console uses.

Limitations:

Because of the way VT100 escape sequences work, the backend is much slower than a regular Windows Console backend (that renders the output directly into the console). If speed is a priority, it is recommended to use the Windows Console backend instead.

Keep in mind that the speed limitation can be mitigated by using a 3rd-party terminal that uses the GPU to render the output, such as:

Usage

Windows VT is not the default backend on Windows. To use it, you need to specify the WindowsVT backend type when creating the application:

use appcui::prelude::*;

fn main() -> Result<(), appcui::system::Error> {
    App::new()
        .backend(appcui::backend::Type::WindowsVT)
        .window(|| window!("'Demo',a:c,w:30,h:9"))
        .run()
}

Furthermore, if you also want to use true colors, you will need to enable the TRUE_COLORS feature when building the application:

[dependencies]
appcui = { version = "*", features = ["TRUE_COLORS"] }