]> 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 f972c378397ffe14a5ce238fcfb02043ffe5d3e8..a197f80a40f6606ec42091236c5b96dd18886afd 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implements editor interface functions.\r
 \r
 /** @file\r
   Implements editor interface functions.\r
 \r
-  Copyright (c) 2005 - 2014, 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
   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
 {\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
   \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
     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
   //\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
 \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
   //\r
   // update screen with file buffer's info\r
   //\r
@@ -1407,6 +1434,7 @@ EFI_EDITOR_GLOBAL_EDITOR      MainEditorConst = {
     0\r
   },\r
   NULL,\r
     0\r
   },\r
   NULL,\r
+  NULL,\r
   FALSE,\r
   NULL\r
 };\r
   FALSE,\r
   NULL\r
 };\r
@@ -1418,7 +1446,6 @@ EFI_EDITOR_GLOBAL_EDITOR      MainEditorConst = {
   @retval EFI_LOAD_ERROR          A load error occured.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_LOAD_ERROR          A load error occured.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 MainEditorInit (\r
   VOID\r
   )\r
 MainEditorInit (\r
   VOID\r
   )\r
@@ -1453,6 +1480,19 @@ MainEditorInit (
         &(MainEditor.ScreenSize.Row)\r
         );\r
 \r
         &(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
   //\r
   // Find mouse in System Table ConsoleInHandle\r
   //\r
@@ -1522,7 +1562,7 @@ MainEditorInit (
     return EFI_LOAD_ERROR;\r
   }\r
 \r
     return EFI_LOAD_ERROR;\r
   }\r
 \r
-  InputBarInit ();\r
+  InputBarInit (MainEditor.TextInputEx);\r
 \r
   Status = FileBufferInit ();\r
   if (EFI_ERROR (Status)) {\r
 \r
   Status = FileBufferInit ();\r
   if (EFI_ERROR (Status)) {\r
@@ -1552,7 +1592,6 @@ MainEditorInit (
   @retval EFI_LOAD_ERROR          A load error occured.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_LOAD_ERROR          A load error occured.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 MainEditorCleanup (\r
   VOID\r
   )\r
 MainEditorCleanup (\r
   VOID\r
   )\r
@@ -1596,7 +1635,6 @@ MainEditorCleanup (
   Refresh the main editor component.\r
 **/\r
 VOID\r
   Refresh the main editor component.\r
 **/\r
 VOID\r
-EFIAPI\r
 MainEditorRefresh (\r
   VOID\r
   )\r
 MainEditorRefresh (\r
   VOID\r
   )\r
@@ -1617,8 +1655,8 @@ MainEditorRefresh (
 \r
     MainTitleBarRefresh (MainEditor.FileBuffer->FileName, MainEditor.FileBuffer->FileType, MainEditor.FileBuffer->ReadOnly, MainEditor.FileBuffer->FileModified, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row, 0, 0);\r
     FileBufferRestorePosition ();\r
 \r
     MainTitleBarRefresh (MainEditor.FileBuffer->FileName, MainEditor.FileBuffer->FileType, MainEditor.FileBuffer->ReadOnly, MainEditor.FileBuffer->FileModified, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row, 0, 0);\r
     FileBufferRestorePosition ();\r
-    FileBufferRefresh ();\r
   }\r
   }\r
+\r
   if (EditorFirst\r
     || FileBufferBackupVar.FilePosition.Row != FileBuffer.FilePosition.Row \r
     || FileBufferBackupVar.FilePosition.Column != FileBuffer.FilePosition.Column \r
   if (EditorFirst\r
     || FileBufferBackupVar.FilePosition.Row != FileBuffer.FilePosition.Row \r
     || FileBufferBackupVar.FilePosition.Column != FileBuffer.FilePosition.Column \r
@@ -1627,13 +1665,14 @@ MainEditorRefresh (
 \r
     StatusBarRefresh (EditorFirst, MainEditor.ScreenSize.Row, MainEditor.ScreenSize.Column, MainEditor.FileBuffer->FilePosition.Row, MainEditor.FileBuffer->FilePosition.Column, MainEditor.FileBuffer->ModeInsert);\r
     FileBufferRestorePosition ();\r
 \r
     StatusBarRefresh (EditorFirst, MainEditor.ScreenSize.Row, MainEditor.ScreenSize.Column, MainEditor.FileBuffer->FilePosition.Row, MainEditor.FileBuffer->FilePosition.Column, MainEditor.FileBuffer->ModeInsert);\r
     FileBufferRestorePosition ();\r
-    FileBufferRefresh ();\r
   }\r
 \r
   if (EditorFirst) {\r
     FileBufferRestorePosition ();\r
   }\r
 \r
   }\r
 \r
   if (EditorFirst) {\r
     FileBufferRestorePosition ();\r
   }\r
 \r
+  FileBufferRefresh ();\r
+\r
   //\r
   // EditorFirst is now set to FALSE\r
   //\r
   //\r
   // EditorFirst is now set to FALSE\r
   //\r
@@ -1648,7 +1687,6 @@ MainEditorRefresh (
   @return The X location of the mouse.\r
 **/\r
 INT32\r
   @return The X location of the mouse.\r
 **/\r
 INT32\r
-EFIAPI\r
 GetTextX (\r
   IN INT32 GuidX\r
   )\r
 GetTextX (\r
   IN INT32 GuidX\r
   )\r
@@ -1670,7 +1708,6 @@ GetTextX (
   @return The Y location of the mouse.\r
 **/\r
 INT32\r
   @return The Y location of the mouse.\r
 **/\r
 INT32\r
-EFIAPI\r
 GetTextY (\r
   IN INT32 GuidY\r
   )\r
 GetTextY (\r
   IN INT32 GuidY\r
   )\r
@@ -1694,7 +1731,6 @@ GetTextY (
   @retval EFI_NOT_FOUND     There was no mouse support found.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_NOT_FOUND     There was no mouse support found.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 MainEditorHandleMouseInput (\r
   IN EFI_SIMPLE_POINTER_STATE       MouseState\r
   )\r
 MainEditorHandleMouseInput (\r
   IN EFI_SIMPLE_POINTER_STATE       MouseState\r
   )\r
@@ -1795,14 +1831,15 @@ MainEditorHandleMouseInput (
   @retval EFI_OUT_OF_RESOURCES    A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_OUT_OF_RESOURCES    A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 MainEditorKeyInput (\r
   VOID\r
   )\r
 {\r
 MainEditorKeyInput (\r
   VOID\r
   )\r
 {\r
-  EFI_INPUT_KEY             Key;\r
+  EFI_KEY_DATA              KeyData;\r
   EFI_STATUS                Status;\r
   EFI_SIMPLE_POINTER_STATE  MouseState;\r
   EFI_STATUS                Status;\r
   EFI_SIMPLE_POINTER_STATE  MouseState;\r
+  UINTN                     EventIndex;\r
+  BOOLEAN                   NoShiftState;\r
 \r
   do {\r
 \r
 \r
   do {\r
 \r
@@ -1837,46 +1874,52 @@ MainEditorKeyInput (
       }\r
     }\r
 \r
       }\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
         //\r
-        // not already has some error status\r
+        FileBufferMouseNeedRefresh = TRUE;\r
         //\r
         //\r
-        if (StatusBarGetString() != NULL && StrCmp (L"", StatusBarGetString()) == 0) {\r
-          StatusBarSetStatusString (L"Disk Error. Try Again");\r
+        // clear previous status string\r
+        //\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
+      }\r
+      //\r
+      // after handling, refresh editor\r
+      //\r
+      MainEditorRefresh ();\r
     }\r
     }\r
-    //\r
-    // after handling, refresh editor\r
-    //\r
-    MainEditorRefresh ();\r
 \r
   } while (Status != EFI_OUT_OF_RESOURCES && !EditorExit);\r
 \r
 \r
   } while (Status != EFI_OUT_OF_RESOURCES && !EditorExit);\r
 \r
@@ -1892,7 +1935,6 @@ MainEditorKeyInput (
   @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 MainEditorSetCutLine (\r
   EFI_EDITOR_LINE *Line\r
   )\r
 MainEditorSetCutLine (\r
   EFI_EDITOR_LINE *Line\r
   )\r
@@ -1924,7 +1966,6 @@ MainEditorSetCutLine (
   @retval EFI_SUCCESS The operation was successful.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_SUCCESS The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 MainEditorBackup (\r
   VOID\r
   )\r
 MainEditorBackup (\r
   VOID\r
   )\r