parseControl method

Event parseControl(
  1. int b
)

Implementation

Event parseControl(int b) {
  switch (b) {
    case 0x00: // NUL
      if (legacy.has(_flagCtrlAt)) {
        return KeyPressEvent(Key(code: 0x40 /* @ */, mod: KeyMod.ctrl));
      }
      return KeyPressEvent(Key(code: keySpace, mod: KeyMod.ctrl));
    case 0x09: // HT
      if (legacy.has(_flagCtrlI)) {
        return KeyPressEvent(Key(code: 0x69 /* i */, mod: KeyMod.ctrl));
      }
      return KeyPressEvent(Key(code: keyTab));
    case 0x0d: // CR
      if (legacy.has(_flagCtrlM)) {
        return KeyPressEvent(Key(code: 0x6d /* m */, mod: KeyMod.ctrl));
      }
      return KeyPressEvent(Key(code: keyEnter));
    case 0x1b: // ESC
      if (legacy.has(_flagCtrlOpenBracket)) {
        return KeyPressEvent(Key(code: 0x5b /* [ */, mod: KeyMod.ctrl));
      }
      return KeyPressEvent(Key(code: keyEscape));
    case 0x7f: // DEL
      if (legacy.has(_flagBackspace)) {
        return KeyPressEvent(Key(code: keyDelete));
      }
      return KeyPressEvent(Key(code: keyBackspace));
    case 0x20: // SP
      return KeyPressEvent(Key(code: keySpace, text: ' '));
    default:
      // Map C0 control codes to ctrl+<letter/symbol>.
      if (b >= 0x01 && b <= 0x1a) {
        final code = 0x60 + b; // 'a' - 1 + b
        return KeyPressEvent(Key(code: code, mod: KeyMod.ctrl));
      }
      switch (b) {
        case 0x1c: // FS
          return KeyPressEvent(Key(code: 0x5c /* \\ */, mod: KeyMod.ctrl));
        case 0x1d: // GS
          return KeyPressEvent(Key(code: 0x5d /* ] */, mod: KeyMod.ctrl));
        case 0x1e: // RS
          return KeyPressEvent(Key(code: 0x5e /* ^ */, mod: KeyMod.ctrl));
        case 0x1f: // US
          return KeyPressEvent(Key(code: 0x5f /* _ */, mod: KeyMod.ctrl));
      }
      return UnknownEvent(String.fromCharCode(b));
  }
}