keyInput method

  1. @override
void keyInput(
  1. TerminalKey key, {
  2. bool ctrl = false,
  3. bool alt = false,
  4. bool shift = false,
  5. bool mac = false,
  6. String? character,
})
override

notifies the Terminal about key input

Implementation

@override
void keyInput(
  TerminalKey key, {
  bool ctrl = false,
  bool alt = false,
  bool shift = false,
  bool mac = false,
  // bool meta,
  String? character,
}) {
  debug.onMsg(key);

  for (var record in keytab.records) {
    if (record.key != key) {
      continue;
    }

    if (record.ctrl != null && record.ctrl != ctrl) {
      continue;
    }

    if (record.shift != null && record.shift != shift) {
      continue;
    }

    if (record.alt != null && record.alt != alt) {
      continue;
    }

    if (record.anyModifier == true &&
        (ctrl != true && alt != true && shift != true)) {
      continue;
    }

    if (record.anyModifier == false &&
        !(ctrl != true && alt != true && shift != true)) {
      continue;
    }

    if (record.appScreen != null && record.appScreen != isUsingAltBuffer()) {
      continue;
    }

    if (record.newLine != null && record.newLine != newLineMode) {
      continue;
    }

    if (record.appCursorKeys != null &&
        record.appCursorKeys != applicationCursorKeys) {
      continue;
    }

    if (record.mac != null && record.mac != mac) {
      continue;
    }

    // TODO: support VT52
    if (record.ansi == false) {
      continue;
    }

    if (record.action.type == KeytabActionType.input) {
      debug.onMsg('input: ${record.action.value}');
      final input = keytabUnescape(record.action.value);
      backend?.write(input);
      return;
    }
  }

  if (ctrl) {
    if (key.index >= TerminalKey.keyA.index &&
        key.index <= TerminalKey.keyZ.index) {
      final input = key.index - TerminalKey.keyA.index + 1;
      backend?.write(String.fromCharCode(input));
      return;
    }
  }

  if (alt) {
    if (key.index >= TerminalKey.keyA.index &&
        key.index <= TerminalKey.keyZ.index) {
      final charCode = key.index - TerminalKey.keyA.index + 65;

      // only process ALT + Key when this combination has no other meaning
      // (reflected in the given character argument
      if (character == null ||
          character.toLowerCase() ==
              String.fromCharCode(charCode).toLowerCase()) {
        final input = [0x1b, charCode];
        backend?.write(String.fromCharCodes(input));
      }
      return;
    }
  }
}