resize method

  1. @override
void resize({
  1. required int cols,
  2. required int rows,
})
override

Sets the child terminal's window size.

The wrapper records the PTS path a moment after script starts. A resize requested before that — e.g. a client sending its size right after the session opens — is kept and applied as soon as the path appears (polled every 25ms for up to 5s, until the child exits). Only the latest pending size is applied. Without a tty file live resize is disabled (a no-op).

Implementation

@override
void resize({required int cols, required int rows}) {
  if (_ttyFile == null || _exited) return;
  final path = _ttyPath();
  if (path != null) {
    _cancelPending();
    _applySize(path, cols: cols, rows: rows);
    return;
  }
  _pendingSize = (cols: cols, rows: rows);
  if (_pendingTimer != null) return;
  final deadline = DateTime.now().add(_pendingTimeout);
  _pendingTimer = Timer.periodic(_pendingPoll, (_) {
    final size = _pendingSize;
    final ready = _ttyPath();
    if (size == null || _exited) {
      _cancelPending();
    } else if (ready != null) {
      _cancelPending();
      _applySize(ready, cols: size.cols, rows: size.rows);
    } else if (DateTime.now().isAfter(deadline)) {
      _cancelPending();
    }
  });
}