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

Backends

AppCUI supports various backends (but each one comes with advantages and drawbacks). A backend is the layer that takes the information (characters) from AppCUI’s virtual screen and displays it in the terminal.

Each backend supported by AppCUI has the following properties:

  • Output rendering - each character from the AppCUI surface is displayed on the screen
  • Input reading - the backend is capable of identifying keyboard and mouse events and converting them to internal AppCUI events
  • Clipboard support - the backend interacts with the OS and provides functionality for Copy / Cut / Paste using OS APIs

The following backends are supported:

  1. Windows Console
  2. Windows VT (Virtual Terminal)
  3. NCurses
  4. Termios
  5. Web Terminal
  6. CrossTerm

Remarks: These types are available via appcui::backend::Type and can be used to initialize an application.

#![allow(unused)]
fn main() {
App::new().backend(appcui::backend::Type::/*type*/).run()?
}

where the appcui::backend::Type enum is defined as follows:

#![allow(unused)]
fn main() {
pub enum Type {
    #[cfg(target_os = "windows")]
    WindowsConsole,
    #[cfg(target_os = "windows")]
    WindowsVT,
    #[cfg(target_family = "unix")]
    Termios,
    #[cfg(all(target_family = "unix", feature = "NCURSES"))]
    NcursesTerminal,
    #[cfg(target_arch = "wasm32")]
    WebTerminal,
    #[cfg(feature = "CROSSTERM")]
    CrossTerm,
}
}

OS Support

OSWindows ConsoleWindows VTNCursesTermiosWeb TerminalCrossTerm
WindowsYesYes---CROSSTERM
Linux--NCURSESYes-CROSSTERM
macOS--NCURSESYes-CROSSTERM
Web----Yes-

Yes means the backend is compiled in. A feature name means that backend is compiled only when that crate feature is enabled. Termios is built in on Linux and macOS. NCurses and CrossTerm are never selected automatically.

Display

Each backend comes with different support related to what can be displayed on the screen.

  • 16 colors - support for 16 colors for foreground and background
  • True colors - support for true colors (24-bit) for foreground and background
  • UTF-8 - support for UTF-8 encoding
  • Ascii - support for ASCII encoding
  • WTF-16 - support for WTF-16 encoding (a subset of UTF-8) - only for Windows
  • Cursor - support for cursor
  • Cursor Blinking - support for cursor blinking
DisplayWindows ConsoleWindows VTNCursesTermiosWeb TerminalCrossTerm
16 colorsYesYesYesYesYesYes
True colors-Yes-YesYesYes
ASCIIYesYesYesYesYesYes
WTF-16YesYesYesYesYesYes
UTF-8-Yes-YesYesYes
CursorYesYesYesYesYesYes
Cursor BlinkingYesYes---Yes

Remarks:

  1. True colors support requires the feature TRUE_COLORS to be enabled (keep in mind that by doing this you also increase the size of your Color and Character structures - if you don’t need this or your terminal does not support true colors, you will only allocate additional space that will not be used).
  2. Cursor blinking is not supported by all terminals (AppCUI can show or hide the cursor, but it is the terminal’s job to make it blink).

In terms of the output method, each backend uses a different approach:

BackendOutput method
Windows ConsoleDirect output via Windows API
Windows VTANSI sequences
NCursesDirect output via NCurses API. Enable the NCURSES feature and install ncurses on the system.
TermiosANSI sequences
Web TerminalHTML elements and browser APIs
CrossTermANSI sequences (directly via the crossterm crate API)

Character Attributes

Besides background and foreground colors, the following character attributes are supported:

DisplayWindows ConsoleWindows VTNCursesTermiosWeb TerminalCrossTerm
Bold-YesYesYes-Yes
UnderlineYesYesYesYesYesYes
Italic-Yes-Yes-Yes
Curly Underline-Yes-Yes-Yes
Double Underline-Yes-Yes-Yes
Dotted Underline-Yes-Yes-Yes
Strike Through-Yes-Yes-Yes

Input

Capturing the input implies the following capabilities from any backend:

  • identifying keyboard events
  • identifying keyboard combinations such as Alt+Key or Ctrl+Key or Alt+Ctrl+Key
  • Identifying that the state of the Shift, Ctrl and Alt keys has changed (pressed or released)
  • Identifying mouse events
  • Identifying mouse combinations such as Alt+Mouse or Ctrl+Mouse or Alt+Ctrl+Mouse
  • Identifying mouse drag / move events
  • Identifying mouse wheel events

Keyboard

KeysWindows ConsoleWindows VTNCursesTermiosWeb TerminalCrossTerm
Alt+KeyYesYesYesYesYesYes
Shift+KeyYesYesYesYesYesYes
Ctrl+KeyYesYesYesYesYesYes
Alt+Shift+KeyYesYes-Yes--
Ctrl+Shift+KeyYesYes----
Ctrl+Alt+KeyYesYes-Yes--
Ctrl+Alt+Shift+KeyYesYes----
Alt pressedYesYes----
Shift pressedYesYes----
Ctrl pressedYesYes----

Mouse

Mouse eventsWindows ConsoleWindows VTNCursesTermiosWeb TerminalCrossTerm
ClickYesYesYesYesYesYes
Move & DragYesYesYesYesYesYes
WheelYesYesYes-YesYes

Remarks: Input support is highly dependent on the terminal and the OS. Termios maps Alt+Shift and Ctrl+Alt for letters (an ESC prefix) and for CSI keys such as arrows, function keys, Home, End, Page Up, Page Down, Insert, Delete, and Tab. Ctrl+Shift and Ctrl+Alt+Shift on a letter stay in the Ctrl and Ctrl+Alt bytes, so those two rows stay unsupported. See Termios. AppCUI uses the following approach to intercept input:

BackendApproach
Windows ConsoleRead the input directly from the console via Windows API
Windows VTRead the input directly from the console via Windows API
NCursesRead the input directly from the console via NCurses API. Enable the NCURSES feature and install ncurses on the system.
TermiosRead the input directly from the console via Termios API
Web TerminalRead the input directly from the browser
CrossTermRead the input via the crossterm crate API

System events

System events are events that are not related to the keyboard or mouse, but are related to the system and indicate that the console has been changed in some way.

EventsWindows ConsoleWindows VTNCursesTermiosWeb TerminalCrossTerm
Console ResizeYesYesYesYesYesYes
Console ClosedYesYes--Yes-

Other capabilities

CapabilitiesWindows ConsoleWindows VTNCursesTermiosWeb TerminalCrossTerm
Set dimensionYesYes--Yes-
Set titleYesYes--Yes-
Restore screenYesYes--N/A-
Set paletteYesYes-Yes-Yes
Restore paletteYesYes-Yes-Yes
ANSI Based-Yes-Yes-Yes
  • N/A (not applicable) means that there is no original screen prior to the app execution so there is nothing to restore.
  • Restore palette is Yes for Termios and CrossTerm because those backends send OSC 104 on exit. The terminal decides whether those colors actually return. Some terminals, such as WSL, keep the palette that was set. See Termios and CrossTerm.

Panic

If the application panics, AppCUI restores the terminal before Rust prints the panic message. Raw mode is turned off, mouse capture stops, and the cursor is shown. A palette the backend changed is reset the same way as on a normal exit.

Windows Console, Windows VT, Termios, and NCurses keep the last frame on screen and start the panic message on the line under that frame. Windows Console and Windows VT place the cursor on that next line. Termios and NCurses place it at column 0 of the last visible row and print a newline, which scrolls the message under the desktop.

BackendWhat a panic does
Windows ConsoleKeeps the last frame. Moves the cursor to the line under the AppCUI surface and shows the cursor. Restores the console mode and, when it was changed, the 16-color table.
Windows VTKeeps the last frame and places the cursor the same way as Windows Console. Turns mouse tracking off. Sends OSC 104 when the 16 color slots were changed.
TermiosKeeps the last frame. Moves the cursor to column 0 of the last visible row, then prints a newline so the panic message starts under the desktop. Restores the termios modes from before the application, turns mouse tracking off, and shows the cursor. Sends OSC 104 when the 16 color slots were changed.
NCursesKeeps the last frame. Reads the screen height, leaves ncurses with endwin, moves the cursor to column 0 of the last visible row, and prints a newline so the panic message starts under the desktop. endwin restores the tty modes from startup. Turns mouse tracking off and shows the cursor.
CrossTermLeaves the alternate screen, which brings back the terminal contents from before the application. Turns raw mode and mouse capture off, shows the cursor, and resets colors. Prints a blank line, then the panic message. Sends OSC 104 when the 16 color slots were changed.
Web TerminalLeaves the canvas as it is. The panic message is written to the browser console.

A normal exit runs the same mode, mouse, cursor, and palette cleanup. Windows Console and Windows VT then put back the screen from before the application. Termios and NCurses clear the screen. CrossTerm leaves the alternate screen.

The panic example (examples/panic) opens a window with a button that panics.

Clipboard

AppCUI provides clipboard support for copying and pasting text. The clipboard functionality is available on the following backends:

BackendClipboard SupportAPI Used
Windows ConsoleYesWindows API
Windows VTYesWindows API
NCursesYesvia copypasta crate
TermiosYesvia copypasta crate
Web TerminalYesBrowser API
CrossTermYesvia copypasta crate (Linux/macOS) or Windows API (Windows)

Defaults

By default, when initializing an App object via App::new(), the following backend will be used:

OSDefault backendOther available backends
WindowsWindows ConsoleWindows VT, CrossTerm (CROSSTERM)
LinuxTermiosNCurses (NCURSES), CrossTerm (CROSSTERM)
macOSTermiosNCurses (NCURSES), CrossTerm (CROSSTERM)
WebWeb Terminal—

App::new() uses the default backend for the current OS. NCurses and CrossTerm are used only when the matching feature is enabled and .backend(...) selects them.