浏览代码

Input processing, add unicode reading support

Miguel de Icaza 7 年之前
父节点
当前提交
d32972bdff
共有 2 个文件被更改,包括 39 次插入24 次删除
  1. 13 4
      Core.cs
  2. 26 20
      Driver.cs

+ 13 - 4
Core.cs

@@ -64,7 +64,7 @@ namespace Terminal {
         /// </remarks>
         /// </remarks>
         public virtual bool ProcessKey (KeyEvent kb) 
         public virtual bool ProcessKey (KeyEvent kb) 
         { 
         { 
-            return false; 
+            return false;
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -373,6 +373,15 @@ namespace Terminal {
             focused.PositionCursor ();
             focused.PositionCursor ();
         }
         }
 
 
+        public override bool ProcessKey (KeyEvent kb)
+        {
+            if (Focused?.ProcessKey (kb) == true)
+                return true;
+
+            return false;
+        }
+
+
         /// <summary>
         /// <summary>
         /// Finds the first view in the hierarchy that wants to get the focus if nothing is currently focused, otherwise, it does nothing.
         /// Finds the first view in the hierarchy that wants to get the focus if nothing is currently focused, otherwise, it does nothing.
         /// </summary>
         /// </summary>
@@ -523,10 +532,10 @@ namespace Terminal {
             if (ProcessHotKey (kb))
             if (ProcessHotKey (kb))
                 return true;
                 return true;
 
 
-            // Process the key normally
-            if (Focused?.ProcessKey (kb) == true)
+            if (base.ProcessKey (kb))
                 return true;
                 return true;
-
+            
+            // Process the key normally
             if (ProcessColdKey (kb))
             if (ProcessColdKey (kb))
                 return true;
                 return true;
             
             

+ 26 - 20
Driver.cs

@@ -196,31 +196,37 @@ namespace Terminal {
 
 
         void ProcessInput (Responder handler)
         void ProcessInput (Responder handler)
         {
         {
-            var code = Curses.getch ();
-            if ((code == -1) || (code == Curses.KeyResize)) {
-                if (Curses.CheckWinChange ()) {
-                    terminalResized ();
+            int wch;
+            var code = Curses.get_wch (out wch);
+            if (code == Curses.KEY_CODE_YES) {
+                if (wch == Curses.KeyResize) {
+                    if (Curses.CheckWinChange ()) {
+                        terminalResized ();
+                        return;
+                    }
                 }
                 }
-            }
-            if (code == Curses.KeyMouse) {
-                // TODO
-                // Curses.MouseEvent ev;
-                // Curses.getmouse (out ev);
-                // handler.HandleMouse ();
+                if (code == Curses.KeyMouse) {
+                    // TODO
+                    // Curses.MouseEvent ev;
+                    // Curses.getmouse (out ev);
+                    // handler.HandleMouse ();
+                    return;
+                }
+                handler.ProcessKey (new KeyEvent (MapCursesKey (wch)));
                 return;
                 return;
             }
             }
 
 
-            // ESC+letter is Alt-Letter.
-            if (code == 27) {
+            // Special handling for ESC, we want to try to catch ESC+letter to simulate alt-letter.
+            if (wch == 27) {
                 Curses.timeout (100);
                 Curses.timeout (100);
-                int k = Curses.getch ();
-                if (k != Curses.ERR && k != 27) {
-                    var mapped = MapCursesKey (k) | Key.AltMask;
-                    handler.ProcessKey (new KeyEvent (mapped));
-                } 
-            } else {
-                    handler.ProcessKey (new KeyEvent (MapCursesKey (code)));
-            }
+
+                code = Curses.get_wch (out wch);
+                if (code == Curses.KEY_CODE_YES) 
+                    handler.ProcessKey (new KeyEvent (Key.AltMask | MapCursesKey (wch)));
+                if (code == 0)
+                    handler.ProcessKey (new KeyEvent (Key.AltMask | (Key)wch));
+            } else 
+                handler.ProcessKey (new KeyEvent ((Key)wch));
         }
         }
 
 
         public override void PrepareToRun (MainLoop mainLoop, Responder handler)
         public override void PrepareToRun (MainLoop mainLoop, Responder handler)