exec static method

Cmd exec(
  1. String executable,
  2. List<String> arguments, {
  3. required Msg onComplete(
    1. ExecResult result
    ),
  4. String? workingDirectory,
  5. Map<String, String>? environment,
  6. bool releaseTerminal = true,
})

A command that executes an external process.

The TUI program will:

  1. Restore the terminal to normal mode
  2. Run the external process
  3. Re-enter TUI mode
  4. Send onComplete message with the result

This is useful for opening editors, running shell commands, or any external program that needs terminal access.

Set releaseTerminal to false for background helpers. Their output is captured and the TUI keeps processing input and rendering while they run.

// Open a file in the user's editor
Cmd.exec(
  'vim',
  ['/path/to/file.txt'],
  onComplete: (result) => FileEditedMsg(result.exitCode),
)

// Run a shell command
Cmd.exec(
  'git',
  ['status', '--short'],
  onComplete: (result) => GitStatusMsg(result.stdout),
)

Implementation

static Cmd exec(
  String executable,
  List<String> arguments, {
  required Msg Function(ExecResult result) onComplete,
  String? workingDirectory,
  Map<String, String>? environment,
  bool releaseTerminal = true,
}) {
  return Cmd(
    () async => ExecProcessMsg(
      executable: executable,
      arguments: arguments,
      onComplete: onComplete,
      workingDirectory: workingDirectory,
      environment: environment,
      releaseTerminal: releaseTerminal,
    ),
  );
}