View class TUI

View represents a terminal view that can contain metadata for terminal control.

This allows the Model.view method to return more than just a string, enabling declarative control over terminal state like cursor position, window title, and mouse tracking.

The TUI runtime follows The Elm Architecture (TEA) pattern, which separates state, logic, and presentation:

  • Model: The state of your application. It should be immutable.
  • Update: A pure function that takes a Msg and the current Model, and returns a new Model and an optional Cmd.
  • View: A pure function that takes the Model and returns a String (or a View object for advanced metadata) representing the UI.
┌─────────────────────────────────────────────────────┐
│                     Program                          │
│                                                      │
│    ┌───────┐     ┌────────┐     ┌──────┐            │
│    │ Model │────▶│ update │────▶│ view │            │
│    └───────┘     └────────┘     └──────┘            │
│        ▲              │              │               │
│        │              │              ▼               │
│        │         ┌────────┐     ┌────────┐          │
│        └─────────│  Cmd   │     │ Screen │          │
│                  └────────┘     └────────┘          │
│                       │                              │
│                       ▼                              │
│                  ┌────────┐                          │
│                  │  Msg   │◀──── User Input          │
│                  └────────┘                          │
└─────────────────────────────────────────────────────┘

Constructors

View({required String content, Cmd? onMouse(MouseMsg msg)?, Cursor? cursor, Color? backgroundColor, Color? foregroundColor, String? windowTitle, TerminalProgressBar? progressBar, bool? altScreen, bool? reportFocus, bool? bracketedPaste, MouseMode? mouseMode, KeyboardEnhancements? keyboardEnhancements})
const

Properties

altScreen bool?
Optional override for alternate screen buffer mode.
final
backgroundColor Color?
Optional terminal background color.
final
bracketedPaste bool?
Optional override for bracketed paste mode.
final
content String
The screen content of the view.
final
cursor → Cursor?
Optional cursor position and style.
final
foregroundColor Color?
Optional terminal foreground color.
final
hashCode int
The hash code for this object.
no setterinherited
keyboardEnhancements KeyboardEnhancements?
Optional keyboard enhancement features to request from the terminal.
final
mouseMode MouseMode?
Optional override for mouse tracking mode.
final
onMouse Cmd? Function(MouseMsg msg)?
Optional mouse message handler that can be used to intercept mouse messages.
final
progressBar TerminalProgressBar?
Optional terminal progress bar state.
final
reportFocus bool?
Optional override for focus reporting.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
windowTitle String?
Optional terminal window title.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited