Cmd class TUI

A command that produces a message asynchronously.

Commands represent side effects in the TUI architecture. They are async operations that, when complete, may produce a message to be sent back to the Model.update function.

  • Msg: Represents an event (key press, timer tick, network response).
  • Cmd: Represents an effect to be performed by the runtime (quitting, sending a message, running an external process).

Use BatchMsg to group multiple messages, and BatchCmd to group multiple commands.

Built-in Commands

Custom Commands

Create custom commands by providing an async function:

Cmd fetchData() {
  return Cmd(() async {
    final response = await http.get(Uri.parse('https://api.example.com/data'));
    return DataLoadedMsg(response.body);
  });
}
Implementers
Available extensions

Constructors

Cmd(Future<Msg?> _execute())
Creates a command from an async function.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
isActive bool

Available on Cmd?, provided by the CmdExtension extension

Returns true if this command is non-null and not a no-op.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

execute() Future<Msg?>
Executes the command and returns the resulting message (if any).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
orNone() Cmd

Available on Cmd?, provided by the CmdExtension extension

Returns the command or Cmd.none() if null.
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

batch(List<Cmd> commands) Cmd
A command that runs multiple commands concurrently.
clearScreen() Cmd
A command that clears the terminal screen.
delayed(Duration duration, Msg? callback()) Cmd
Sends a message after a delay.
disableBracketedPaste() Cmd
A command that disables bracketed paste mode.
disableMouse() Cmd
A command that disables mouse tracking.
disableReportFocus() Cmd
A command that disables focus reporting.
enableBracketedPaste() Cmd
A command that enables bracketed paste mode.
enableMouseAllMotion() Cmd
A command that enables mouse all motion tracking.
enableMouseCellMotion() Cmd
A command that enables mouse cell motion tracking.
enableReportFocus() Cmd
A command that enables focus reporting.
enterAltScreen() Cmd
A command that enters the alternate screen buffer.
exec(String executable, List<String> arguments, {required Msg onComplete(ExecResult result), String? workingDirectory, Map<String, String>? environment}) Cmd
A command that executes an external process.
exitAltScreen() Cmd
A command that exits the alternate screen buffer.
hideCursor() Cmd
A command that hides the terminal cursor.
listen<T>(Stream<T> stream, {required Msg? onData(T data), Msg? onError(Object error, StackTrace stack)?, Msg? onDone()?}) StreamCmd<T>
A command that listens to a stream and sends messages for each event.
message(Msg msg) Cmd
A command that sends a message immediately.
none() Cmd
A command that does nothing.
openEditor(String filePath, {required Msg onComplete(ExecResult result)}) Cmd
A command that opens an editor for the given file.
openUrl(String url, {required Msg onComplete(ExecResult result)}) Cmd
A command that opens a URL in the default browser.
perform<T>(Future<T> task(), {required Msg onSuccess(T result), Msg onError(Object error, StackTrace stack)?}) Cmd
A command that runs an async function and maps the result to a message.
printf(String format, List<Object> args) Cmd
A command that prints formatted text above the program output.
println(String text) Cmd
A command that prints a line above the program output.
quit() Cmd
A command that signals the program to quit.
repaint({bool force = true}) Cmd
A command that forces a repaint of the view.
requestBackgroundColor() Cmd
Requests the terminal's background color.
requestBackgroundColorReport() Cmd
Requests the terminal background color (OSC 11), plus DA1 as a follow-up.
requestClipboard({String selection = 'c'}) Cmd
Request clipboard content via OSC 52.
requestCursorColor() Cmd
Requests the terminal's cursor color.
requestForegroundColor() Cmd
Requests the terminal's foreground color.
requestTerminalColors() Cmd
Requests terminal foreground/background/cursor color reports (OSC 10/11/12), plus DA1 as a follow-up.
requestWindowSizeReport() Cmd
Request the terminal to report its character cell size (rows/cols).
sequence(List<Cmd> commands) Cmd
A command that runs commands in sequence.
setClipboard(String text, {String selection = 'c'}) Cmd
Set the terminal clipboard via OSC 52.
setWindowTitle(String title) Cmd
A command that sets the terminal window title.
showCursor() Cmd
A command that shows the terminal cursor.
suspend() Cmd
A command that suspends the program.
tick(Duration duration, Msg? callback(DateTime time)) Cmd
A command that sends a message after a delay.
windowSize() Cmd
A command that requests the current window size.
writeRaw(String data) Cmd
A command that writes raw bytes/escape sequences directly to the terminal.