Răsfoiți Sursa

Merge pull request #22 from devmil/feature/handle_mac_input_specialties

Handle mac input specialties
xuty 4 ani în urmă
părinte
comite
6dcd68f63d

+ 1 - 0
lib/frontend/input_behavior_default.dart

@@ -27,6 +27,7 @@ class InputBehaviorDefault extends InputBehavior {
         ctrl: event.isControlPressed,
         alt: event.isAltPressed,
         shift: event.isShiftPressed,
+        mac: terminal.platform.useMacInputBehavior,
       );
     }
   }

+ 12 - 2
lib/input/keytab/keytab_default.dart

@@ -74,8 +74,18 @@ key Left  -Shift-AnyMod+Ansi-AppCuKeys : "\E[D"
 
 key Up    -Shift+AnyMod+Ansi           : "\E[1;5A"
 key Down  -Shift+AnyMod+Ansi           : "\E[1;5B"
-key Right -Shift+AnyMod+Ansi           : "\E[1;5C"
-key Left  -Shift+AnyMod+Ansi           : "\E[1;5D"
+
+# Right / Left with Control
+key Right -Shift-Alt+Control+Ansi      : "\E[1;5C"
+key Left  -Shift-Alt+Control+Ansi      : "\E[1;5D"
+
+# Right / Left with Alt not on a Mac
+key Right -Shift+Alt-Control+Ansi-Mac  : "\E[1;5C"
+key Left  -Shift+Alt-Control+Ansi-Mac  : "\E[1;5D"
+
+# Right / Left with Alt on a Mac
+key Right -Shift+Alt-Control+Ansi+Mac  : "\Ef"
+key Left  -Shift+Alt-Control+Ansi+Mac  : "\Eb"
 
 key Up    +Shift+AppScreen             : "\E[1;*A"
 key Down  +Shift+AppScreen             : "\E[1;*B"

+ 5 - 0
lib/input/keytab/keytab_parse.dart

@@ -91,6 +91,7 @@ class KeytabParser {
     bool? appCursorKeys;
     bool? appKeyPad;
     bool? newLine;
+    bool? mac;
 
     while (reader.peek()!.type == KeytabTokenType.modeStatus) {
       bool modeStatus;
@@ -141,6 +142,9 @@ class KeytabParser {
         case 'NewLine':
           newLine = modeStatus;
           break;
+        case 'Mac':
+          mac = modeStatus;
+          break;
         default:
           throw ParseError();
       }
@@ -174,6 +178,7 @@ class KeytabParser {
       appCursorKeys: appCursorKeys,
       appKeyPad: appKeyPad,
       newLine: newLine,
+      mac: mac,
     );
 
     _records.add(record);

+ 6 - 0
lib/input/keytab/keytab_record.dart

@@ -39,6 +39,7 @@ class KeytabRecord {
     required this.appCursorKeys,
     required this.appKeyPad,
     required this.newLine,
+    required this.mac,
   });
 
   String qtKeyName;
@@ -55,6 +56,7 @@ class KeytabRecord {
   bool? appCursorKeys;
   bool? appKeyPad;
   bool? newLine;
+  bool? mac;
 
   @override
   String toString() {
@@ -101,6 +103,10 @@ class KeytabRecord {
       buffer.write(modeStatus(newLine!, 'NewLine'));
     }
 
+    if (mac != null) {
+      buffer.write(modeStatus(mac!, 'Mac'));
+    }
+
     buffer.write(' : $action');
 
     return buffer.toString();

+ 19 - 3
lib/terminal/platform.dart

@@ -1,10 +1,26 @@
 class PlatformBehavior {
-  const PlatformBehavior({required this.oscTerminators});
+  const PlatformBehavior({
+    required this.oscTerminators,
+    required this.useMacInputBehavior,
+  });
 
   final Set<int> oscTerminators;
+  final bool useMacInputBehavior;
 }
 
 class PlatformBehaviors {
-  static const unix = PlatformBehavior(oscTerminators: {0x07, 0x5c});
-  static const windows = PlatformBehavior(oscTerminators: {0x07, 0x00});
+  static const mac = PlatformBehavior(
+    oscTerminators: {0x07, 0x5c},
+    useMacInputBehavior: true,
+  );
+
+  static const unix = PlatformBehavior(
+    oscTerminators: {0x07, 0x5c},
+    useMacInputBehavior: false,
+  );
+
+  static const windows = PlatformBehavior(
+    oscTerminators: {0x07, 0x00},
+    useMacInputBehavior: false,
+  );
 }

+ 5 - 0
lib/terminal/terminal.dart

@@ -361,6 +361,7 @@ class Terminal with Observable {
     bool ctrl = false,
     bool alt = false,
     bool shift = false,
+    bool mac = false,
     // bool meta,
   }) {
     debug.onMsg(key);
@@ -405,6 +406,10 @@ class Terminal with Observable {
         continue;
       }
 
+      if (record.mac != null && record.mac != mac) {
+        continue;
+      }
+
       // TODO: support VT52
       if (record.ansi == false) {
         continue;