]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c
ShellPkg/[hex]edit: use SimpleTextInEx to read console
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Edit / MainTextEditor.c
index 14f51dff19bad261edbe1d93ce86e75e3a0206c3..a197f80a40f6606ec42091236c5b96dd18886afd 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implements editor interface functions.\r
 \r
-  Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -1362,7 +1362,9 @@ MainCommandDisplayHelp (
 {\r
   INT32           CurrentLine;\r
   CHAR16          *InfoString;\r
-  EFI_INPUT_KEY   Key;\r
+  EFI_KEY_DATA    KeyData;\r
+  EFI_STATUS      Status;\r
+  UINTN           EventIndex;\r
   \r
   //\r
   // print helpInfo      \r
@@ -1371,14 +1373,39 @@ MainCommandDisplayHelp (
     InfoString = HiiGetString(gShellDebug1HiiHandle, MainMenuHelpInfo[CurrentLine], NULL);\r
     ShellPrintEx (0, CurrentLine+1, L"%E%s%N", InfoString);        \r
   }\r
-  \r
+\r
   //\r
   // scan for ctrl+w\r
   //\r
-  do {\r
-    gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-  } while(SCAN_CONTROL_W != Key.UnicodeChar); \r
+  while (TRUE) {\r
+    Status = gBS->WaitForEvent (1, &MainEditor.TextInputEx->WaitForKeyEx, &EventIndex);\r
+    if (EFI_ERROR (Status) || (EventIndex != 0)) {\r
+      continue;\r
+    }\r
+    Status = MainEditor.TextInputEx->ReadKeyStrokeEx (MainEditor.TextInputEx, &KeyData);\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
 \r
+    if ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) {\r
+      //\r
+      // For consoles that don't support shift state reporting,\r
+      // CTRL+W is translated to L'W' - L'A' + 1.\r
+      //\r
+      if (KeyData.Key.UnicodeChar == L'W' - L'A' + 1) {\r
+        break;\r
+      }\r
+    } else if (((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) != 0) &&\r
+               ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID | EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) == 0)) {\r
+      //\r
+      // For consoles that supports shift state reporting,\r
+      // make sure that only CONTROL shift key is pressed.\r
+      //\r
+      if ((KeyData.Key.UnicodeChar == 'w') || (KeyData.Key.UnicodeChar == 'W')) {\r
+        break;\r
+      }\r
+    }\r
+  }\r
   //\r
   // update screen with file buffer's info\r
   //\r
@@ -1407,6 +1434,7 @@ EFI_EDITOR_GLOBAL_EDITOR      MainEditorConst = {
     0\r
   },\r
   NULL,\r
+  NULL,\r
   FALSE,\r
   NULL\r
 };\r
@@ -1452,6 +1480,19 @@ MainEditorInit (
         &(MainEditor.ScreenSize.Row)\r
         );\r
 \r
+  //\r
+  // Find TextInEx in System Table ConsoleInHandle\r
+  // Per UEFI Spec, TextInEx is required for a console capable platform.\r
+  //\r
+  Status = gBS->HandleProtocol (\r
+              gST->ConsoleInHandle,\r
+              &gEfiSimpleTextInputExProtocolGuid,\r
+              (VOID**)&MainEditor.TextInputEx\r
+              );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Find mouse in System Table ConsoleInHandle\r
   //\r
@@ -1521,7 +1562,7 @@ MainEditorInit (
     return EFI_LOAD_ERROR;\r
   }\r
 \r
-  InputBarInit ();\r
+  InputBarInit (MainEditor.TextInputEx);\r
 \r
   Status = FileBufferInit ();\r
   if (EFI_ERROR (Status)) {\r
@@ -1794,9 +1835,11 @@ MainEditorKeyInput (
   VOID\r
   )\r
 {\r
-  EFI_INPUT_KEY             Key;\r
+  EFI_KEY_DATA              KeyData;\r
   EFI_STATUS                Status;\r
   EFI_SIMPLE_POINTER_STATE  MouseState;\r
+  UINTN                     EventIndex;\r
+  BOOLEAN                   NoShiftState;\r
 \r
   do {\r
 \r
@@ -1831,46 +1874,52 @@ MainEditorKeyInput (
       }\r
     }\r
 \r
-    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-    if (!EFI_ERROR (Status)) {\r
-      //\r
-      // dispatch to different components' key handling function\r
-      // so not everywhere has to set this variable\r
-      //\r
-      FileBufferMouseNeedRefresh = TRUE;\r
-      //\r
-      // clear previous status string\r
-      //\r
-      StatusBarSetRefresh();\r
-\r
-      //\r
-      // dispatch to different components' key handling function\r
-      //\r
-      if (EFI_NOT_FOUND != MenuBarDispatchControlHotKey(&Key)) {\r
-        Status = EFI_SUCCESS;\r
-      } else if ((Key.ScanCode == SCAN_NULL) || ((Key.ScanCode >= SCAN_UP) && (Key.ScanCode <= SCAN_PAGE_DOWN))) {\r
-        Status = FileBufferHandleInput (&Key);\r
-      } else if ((Key.ScanCode >= SCAN_F1) && (Key.ScanCode <= SCAN_F12)) {\r
-        Status = MenuBarDispatchFunctionKey (&Key);\r
-      } else {\r
-        StatusBarSetStatusString (L"Unknown Command");\r
-        FileBufferMouseNeedRefresh = FALSE;  \r
-      }\r
-      \r
-      if (Status != EFI_SUCCESS && Status != EFI_OUT_OF_RESOURCES) {\r
+    Status = gBS->WaitForEvent (1, &MainEditor.TextInputEx->WaitForKeyEx, &EventIndex);\r
+    if (!EFI_ERROR (Status) && EventIndex == 0) {\r
+      Status = MainEditor.TextInputEx->ReadKeyStrokeEx (MainEditor.TextInputEx, &KeyData);\r
+      if (!EFI_ERROR (Status)) {\r
+        //\r
+        // dispatch to different components' key handling function\r
+        // so not everywhere has to set this variable\r
+        //\r
+        FileBufferMouseNeedRefresh = TRUE;\r
         //\r
-        // not already has some error status\r
+        // clear previous status string\r
         //\r
-        if (StatusBarGetString() != NULL && StrCmp (L"", StatusBarGetString()) == 0) {\r
-          StatusBarSetStatusString (L"Disk Error. Try Again");\r
+        StatusBarSetRefresh();\r
+        //\r
+        // NoShiftState: TRUE when no shift key is pressed.\r
+        //\r
+        NoShiftState = ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) || (KeyData.KeyState.KeyShiftState == EFI_SHIFT_STATE_VALID);\r
+        //\r
+        // dispatch to different components' key handling function\r
+        //\r
+        if (EFI_NOT_FOUND != MenuBarDispatchControlHotKey(&KeyData)) {\r
+          Status = EFI_SUCCESS;\r
+        } else if (NoShiftState && ((KeyData.Key.ScanCode == SCAN_NULL) || ((KeyData.Key.ScanCode >= SCAN_UP) && (KeyData.Key.ScanCode <= SCAN_PAGE_DOWN)))) {\r
+          Status = FileBufferHandleInput (&KeyData.Key);\r
+        } else if (NoShiftState && (KeyData.Key.ScanCode >= SCAN_F1) && (KeyData.Key.ScanCode <= SCAN_F12)) {\r
+          Status = MenuBarDispatchFunctionKey (&KeyData.Key);\r
+        } else {\r
+          StatusBarSetStatusString (L"Unknown Command");\r
+          FileBufferMouseNeedRefresh = FALSE;  \r
+        }\r
+        \r
+        if (Status != EFI_SUCCESS && Status != EFI_OUT_OF_RESOURCES) {\r
+          //\r
+          // not already has some error status\r
+          //\r
+          if (StatusBarGetString() != NULL && StrCmp (L"", StatusBarGetString()) == 0) {\r
+            StatusBarSetStatusString (L"Disk Error. Try Again");\r
+          }\r
         }\r
-      }\r
 \r
+      }\r
+      //\r
+      // after handling, refresh editor\r
+      //\r
+      MainEditorRefresh ();\r
     }\r
-    //\r
-    // after handling, refresh editor\r
-    //\r
-    MainEditorRefresh ();\r
 \r
   } while (Status != EFI_OUT_OF_RESOURCES && !EditorExit);\r
 \r