exec static method
A command that executes an external process.
The TUI program will:
- Restore the terminal to normal mode
- Run the external process
- Re-enter TUI mode
- Send
onCompletemessage with the result
This is useful for opening editors, running shell commands, or any external program that needs terminal access.
// 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,
}) {
return Cmd(
() async => ExecProcessMsg(
executable: executable,
arguments: arguments,
onComplete: onComplete,
workingDirectory: workingDirectory,
environment: environment,
),
);
}