feed method

bool feed(
  1. List<int> chunk
)

Feeds a chunk of remote output. Returns true when inAltScreen changed as a result. Never modifies or consumes the forwarded bytes.

Implementation

bool feed(List<int> chunk) {
  final window = _carry.isEmpty ? chunk : [..._carry, ...chunk];
  final before = inAltScreen;

  for (var i = 0; i < window.length; i++) {
    if (_matchAt(window, i, _enter1049) || _matchAt(window, i, _enter1047)) {
      inAltScreen = true;
    } else if (_matchAt(window, i, _leave1049) ||
        _matchAt(window, i, _leave1047)) {
      inAltScreen = false;
    }
  }

  // Retain a trailing suffix that could be the prefix of a split sequence.
  _carry
    ..clear()
    ..addAll(
      window.length <= _maxSeqLen - 1
          ? window
          : window.sublist(window.length - (_maxSeqLen - 1)),
    );

  return inAltScreen != before;
}