feed method
Takes bytes as the terminal takes what an application writes:
prints their text, runs their control sequences. A sequence cut off at
the end of bytes waits for the rest in the next call.
Implementation
void feed(List<int> bytes) {
var i = 0;
final text = <int>[];
void flushText() {
if (text.isEmpty) {
return;
}
_print(_utf8.convert(text));
text.clear();
}
final data = <int>[..._pending, ...bytes];
_pending.clear();
while (i < data.length) {
final b = data[i];
if (b == 0x1B) {
flushText();
final end = _escape(data, i);
if (end < 0) {
_pending.addAll(data.sublist(i));
return;
}
i = end;
} else if (b == 0x0D) {
flushText();
cx = 0;
pendingWrap = false;
i++;
} else if (b == 0x0A && allowLineFeed) {
flushText();
pendingWrap = false;
_lineFeed();
i++;
} else if (b < 0x20 || b == 0x7F) {
flushText();
_err('raw control byte 0x${b.toRadixString(16)}');
i++;
} else {
text.add(b);
i++;
}
}
flushText();
}