run static method

Future<ScrollingProcessResult> run(
  1. String executable,
  2. List<String> arguments, {
  3. required InlineTerminal terminal,
  4. String? workingDirectory,
  5. Map<String, String>? environment,
  6. bool includeParentEnvironment = true,
  7. bool runInShell = false,
  8. int rows = 5,
  9. bool dim = true,
  10. String? heading,
  11. String? successMessage,
  12. String? failedMessage,
  13. bool captureOutput = false,
})

Starts executable with arguments and renders its output in a scrolling section of rows visual rows until the process completes.

Returns once the process has exited and all of its output has been rendered. The caller then decides whether to ScrollingProcessResult.keep or ScrollingProcessResult.clear the section.

terminal is supplied and owned by the caller; this method does not dispose it.

Implementation

static Future<ScrollingProcessResult> run(
  final String executable,
  final List<String> arguments, {
  required final InlineTerminal terminal,
  final String? workingDirectory,
  final Map<String, String>? environment,
  final bool includeParentEnvironment = true,
  final bool runInShell = false,
  final int rows = 5,
  final bool dim = true,
  final String? heading,
  final String? successMessage,
  final String? failedMessage,
  final bool captureOutput = false,
}) async {
  final section = ScrollingSection(
    terminal: terminal,
    rows: rows,
    dim: dim,
    heading: heading,
    successMessage: successMessage,
    failedMessage: failedMessage,
    captureOutput: captureOutput,
  );

  try {
    final process = await Process.start(
      executable,
      arguments,
      workingDirectory: workingDirectory,
      environment: environment,
      includeParentEnvironment: includeParentEnvironment,
      runInShell: runInShell,
    );

    final stdoutDone = _tail(process.stdout, section);
    final stderrDone = _tail(process.stderr, section);

    final exitCode = await process.exitCode;
    // Ensure all buffered output has been rendered before returning.
    await stdoutDone;
    await stderrDone;

    return ScrollingProcessResult(exitCode: exitCode, section: section);
  } on Object {
    // Restore the cursor and keep whatever was rendered so far.
    section.keep();
    rethrow;
  }
}