Guides/Commands

Commands

A Cmd is a FutureOr<Msg?> Function() — fire-and-forget async work whose result arrives back as the next message. Commands are how you do timers, HTTP, subprocesses and terminal control without breaking purity.

Built-in helpers

dart
Msg quit()
Msg interrupt()
Cmd tick(Duration d, Msg Function(DateTime) fn)       // one-shot delay
Cmd every(Duration d, Msg Function(DateTime) fn)      // repeating, wall-clock aligned
Cmd? batch(List<Cmd?> cmds)                           // concurrent
Cmd? sequence(List<Cmd?> cmds)                        // sequential
Cmd execProcess(String exe, List<String> args, {...}) // external process
Cmd requestBackgroundColor()                          // fire OSC 11 query manually

Terminal control

dart
Msg enterAltScreen()       // switch to alt screen buffer
Msg exitAltScreen()        // return to primary screen
Msg hideCursor()           // hide terminal cursor
Msg showCursor()           // show terminal cursor
Cmd setWindowTitle(title)  // set window/tab title via OSC
Msg clearScrollArea()      // clear screen and scrollback
Cmd scrollUp([int n = 1])  // scroll viewport up n lines
Cmd scrollDown([int n = 1])// scroll viewport down n lines
Commands are fire-and-forget: dart_tui runs them off the event loop and enqueues their returned Msg when they complete. Return batch([...]) to run several at once, or sequence([...]) to chain them.

Related