init method Null safety

void init()

Initialize Keyboard System

Implementation

static void init() {
  if (!_initialized) {
    stdin.echoMode = false;
    stdin.lineMode = false;
    _initialized = true;

    Console.adapter.byteStream().asBroadcastStream().map((bytes) {
      var it = ascii.decode(bytes);
      var original = bytes;
      var code = it.replaceAll(Console.ANSI_CODE, '');

      if (code.isNotEmpty) {
        code = code.substring(1);
      }

      if (_inputSequences[code] != null) {
        return [original, _inputSequences[code]];
      } else {
        return [original, it];
      }
    }).listen((List<dynamic> m) {
      handleKey(m[0], m[1]);
    });
  }
}