readByteSync method

int? readByteSync()

Use this to read a byte, whether in mock mode or with real stdin.

Implementation

int? readByteSync() {
  if (mock) {
    var ret = _mockBuffer[0];
    _mockBuffer.removeAt(0);
    return (ret is int ? ret : int.parse(ret));
  }
  int? key;
  if (Platform.isWindows) {
    var keyInput = console.readKey().toString();
    if (keyInput.startsWith('ControlCharacter')) {
      keyInput = keyInput.split('.')[1];
      if (keyInput == 'arrowUp') {
        return winUp;
      } else if (keyInput == 'arrowDown') {
        return winDown;
      } else if (keyInput == 'enter') {
        return winEnter;
      }
    } else {
      return keyInput.codeUnitAt(0);
    }
  } else {
    key = stdin.readByteSync();
  }
  return key;
}