spawn method

void spawn(
  1. String command, {
  2. List<String>? args,
  3. Map<String, String>? environment,
})

Implementation

void spawn(
  String command, {
  List<String>? args,
  Map<String, String>? environment,
}) {
  if (_state == GhosttyTerminalPtySessionState.closed) {
    throw StateError('Session is closed.');
  }
  if (_state == GhosttyTerminalPtySessionState.running) {
    throw StateError('Process already running.');
  }

  _closePty();
  _exitCode = null;
  _rows = _config.rows;
  _cols = _config.cols;

  final pty = PortablePty.open(
    rows: _rows,
    cols: _cols,
    transport: _config.transport,
  );
  _pty = pty;
  pty.spawn(command, args: args, environment: environment);
  _setNonBlocking(pty.masterFd);
  _setState(GhosttyTerminalPtySessionState.running);
  _startReadLoop();
}