parseAll method
Parses input bytes and returns any decoded events.
When expired=false, short ESC-prefixed sequences are held in the buffer
so they can be completed by subsequent reads.
When expired=true, incomplete sequences are flushed (e.g. at EOF or after
an escape timeout).
Implementation
List<Event> parseAll(List<int> bytes, {bool expired = false}) {
if (bytes.isNotEmpty) _buffer.addAll(bytes);
final out = <Event>[];
_deserializeWin32VtInputMode();
while (_buffer.isNotEmpty) {
if (_inPaste) {
final ev = _consumePasteIfComplete(expired: expired);
if (ev == null) break;
out.add(ev);
continue;
}
final esc = _buffer.isNotEmpty && _buffer[0] == 0x1b;
final (n, ev) = _decoder.decode(_buffer, allowIncompleteEsc: expired);
if (n == 0) break;
// Upstream `TerminalReader` waits before committing ESC-prefixed sequences
// shorter than 3 bytes.
if (esc && n <= 2 && !expired) break;
// If the decoder reported an unknown event and we haven't expired yet,
// assume it may be incomplete and wait for more bytes.
if (ev is UnknownEvent && !expired) break;
_buffer.removeRange(0, n);
if (ev == null) continue;
if (ev is IgnoredEvent) continue;
if (ev is PasteStartEvent) {
_inPaste = true;
_pasteBytes.clear();
continue;
}
if (ev is PasteEndEvent) {
_inPaste = false;
out.add(const PasteEvent(''));
continue;
}
if (ev is MultiEvent) {
out.addAll(ev.events);
} else {
out.add(ev);
}
}
return out;
}