write method

Future write(
  1. List<int> bytes
)

writes the given bytes to the console

Implementation

Future write(List<int> bytes) async {
  // make sure that only one write is active at a time (needed for flush to work)
  if (_writeCompleter != null) {
    await _writeCompleter!.future;
  }
  _writeCompleter = Completer();
  final localCompleter = _writeCompleter!;

  String stringContent = _utf8Decoder.convert(bytes);
  if (_currentWindowSize != null) {
    if (stringContent.length > 1 && stringContent.endsWith('\n')) {
      stringContent = stringContent.substring(0, stringContent.length - 1);
    }
    _windowLines.addAll(stringContent.split('\n'));
    while (_windowLines.length > _currentWindowSize!) {
      _windowLines.removeAt(0);
    }
    _drawWindow();
    await stdout.flush();
  } else {
    Console.write(stringContent);
  }

  _writeCompleter = null;
  localCompleter.complete();
}