Pārlūkot izejas kodu

Merge pull request #19 from devmil/feature/handle_mac_input_specialties

Fixes Option + Left/Right for Macs
xuty 4 gadi atpakaļ
vecāks
revīzija
9286d8c8f6

+ 7 - 6
lib/frontend/input_behavior_default.dart

@@ -1,3 +1,5 @@
+import 'dart:io';
+
 import 'package:flutter/services.dart';
 import 'package:flutter/widgets.dart';
 import 'package:xterm/frontend/input_behavior.dart';
@@ -22,12 +24,11 @@ class InputBehaviorDefault extends InputBehavior {
     final key = inputMap(event.logicalKey);
 
     if (key != null) {
-      terminal.keyInput(
-        key,
-        ctrl: event.isControlPressed,
-        alt: event.isAltPressed,
-        shift: event.isShiftPressed,
-      );
+      terminal.keyInput(key,
+          ctrl: event.isControlPressed,
+          alt: event.isAltPressed,
+          shift: event.isShiftPressed,
+          mac: Platform.isMacOS);
     }
   }
 

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

@@ -74,8 +74,11 @@ 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"
+key Right -Shift+AnyMod+Ansi-Mac       : "\E[1;5C"
+key Left  -Shift+AnyMod+Ansi-Mac       : "\E[1;5D"
+
+key Right -Shift+AnyMod+Ansi+Mac       : "\Ef"
+key Left  -Shift+AnyMod+Ansi+Mac       : "\Eb"
 
 key Up    +Shift+AppScreen             : "\E[1;*A"
 key Down  +Shift+AppScreen             : "\E[1;*B"

+ 18 - 14
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();
       }
@@ -161,20 +165,20 @@ class KeytabParser {
     }
 
     final record = KeytabRecord(
-      qtKeyName: keyName.value,
-      key: key,
-      action: action,
-      alt: alt,
-      ctrl: ctrl,
-      shift: shift,
-      anyModifier: anyModifier,
-      ansi: ansi,
-      appScreen: appScreen,
-      keyPad: keyPad,
-      appCursorKeys: appCursorKeys,
-      appKeyPad: appKeyPad,
-      newLine: newLine,
-    );
+        qtKeyName: keyName.value,
+        key: key,
+        action: action,
+        alt: alt,
+        ctrl: ctrl,
+        shift: shift,
+        anyModifier: anyModifier,
+        ansi: ansi,
+        appScreen: appScreen,
+        keyPad: keyPad,
+        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();

+ 5 - 0
lib/terminal/terminal.dart

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