]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/[hex]edit: use SimpleTextInEx to read console
authorRuiyu Ni <ruiyu.ni@intel.com>
Mon, 12 Feb 2018 13:42:55 +0000 (21:42 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Tue, 13 Feb 2018 02:54:45 +0000 (10:54 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=682

Edit and HexEdit commands assume that SimpleTxtIn translates
Ctrl+<Alpha-Key> key combinations into Unicode control characters
(0x1-0x1A).

Such translation does not seem to be required by the UEFI spec.
Shell should not rely on implementation specific behavior.
It should instead use SimpleTextInEx to read Ctrl+<Alpha-Key> key
combinations.

The patch changes edit and hexedit to only consumes SimpleTextInEx
so that the implementation specific behavior dependency is removed.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reported-by: Felix <felixp@mail.ru>
Cc: Felix <felixp@mail.ru>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c
ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditorTypes.h
ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c
ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.h
ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c
ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.h
ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEditorTypes.h
ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c

index 14f51dff19bad261edbe1d93ce86e75e3a0206c3..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 - 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
   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
@@ -1452,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
@@ -1521,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
@@ -1794,9 +1835,11 @@ MainEditorKeyInput (
   VOID\r
   )\r
 {\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
@@ -1831,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
+        FileBufferMouseNeedRefresh = TRUE;\r
         //\r
         //\r
-        // not already has some error status\r
+        // clear previous status string\r
         //\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
+      }\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
index dfd56dd9a6eced196624b41a58853498c5670301..4cabba7b1321bda528a387bd573e3e62c42bf8be 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Declares editor types.\r
 \r
 /** @file\r
   Declares editor types.\r
 \r
-  Copyright (c) 2005 - 2011, 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
@@ -87,15 +87,16 @@ typedef struct {
 } EFI_EDITOR_FILE_BUFFER;\r
 \r
 typedef struct {\r
 } EFI_EDITOR_FILE_BUFFER;\r
 \r
 typedef struct {\r
-  EFI_EDITOR_FILE_BUFFER      *FileBuffer;\r
-\r
-  EFI_EDITOR_COLOR_UNION      ColorAttributes;\r
-  EFI_EDITOR_POSITION         ScreenSize; // row number and column number\r
-  EFI_EDITOR_LINE             *CutLine;   // clip board\r
-  BOOLEAN                     MouseSupported;\r
-  EFI_SIMPLE_POINTER_PROTOCOL *MouseInterface;\r
-  INT32                       MouseAccumulatorX;\r
-  INT32                       MouseAccumulatorY;\r
+  EFI_EDITOR_FILE_BUFFER            *FileBuffer;\r
+\r
+  EFI_EDITOR_COLOR_UNION            ColorAttributes;\r
+  EFI_EDITOR_POSITION               ScreenSize; // row number and column number\r
+  EFI_EDITOR_LINE                   *CutLine;   // clip board\r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInputEx;\r
+  BOOLEAN                           MouseSupported;\r
+  EFI_SIMPLE_POINTER_PROTOCOL       *MouseInterface;\r
+  INT32                             MouseAccumulatorX;\r
+  INT32                             MouseAccumulatorY;\r
 \r
 } EFI_EDITOR_GLOBAL_EDITOR;\r
 \r
 \r
 } EFI_EDITOR_GLOBAL_EDITOR;\r
 \r
index 26f70d719ab3f0cb79208401c6cfec65d00ec516..6c6fc70bab4aee1ead43a7603ec59b1bf8d7bc44 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implements inputbar interface functions.\r
 \r
 /** @file\r
   Implements inputbar 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
 CHAR16  *mPrompt;        // Input bar mPrompt string.\r
 CHAR16  *mReturnString;  // The returned string.\r
 UINTN   StringSize;      // Size of mReturnString space size.\r
 CHAR16  *mPrompt;        // Input bar mPrompt string.\r
 CHAR16  *mReturnString;  // The returned string.\r
 UINTN   StringSize;      // Size of mReturnString space size.\r
+EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *mTextInEx;\r
 \r
 /**\r
   Initialize the input bar.\r
 \r
 /**\r
   Initialize the input bar.\r
+\r
+  @param[in] TextInEx  Pointer to SimpleTextInEx instance in System Table.\r
 **/\r
 VOID\r
 InputBarInit (\r
 **/\r
 VOID\r
 InputBarInit (\r
-  VOID\r
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx\r
   )\r
 {\r
   mPrompt       = NULL;\r
   mReturnString = NULL;\r
   StringSize    = 0;\r
   )\r
 {\r
   mPrompt       = NULL;\r
   mReturnString = NULL;\r
   StringSize    = 0;\r
+  mTextInEx     = TextInEx;\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -125,7 +129,7 @@ InputBarRefresh (
 {\r
   INPUT_BAR_COLOR_UNION   Orig;\r
   INPUT_BAR_COLOR_UNION   New;\r
 {\r
   INPUT_BAR_COLOR_UNION   Orig;\r
   INPUT_BAR_COLOR_UNION   New;\r
-  EFI_INPUT_KEY           Key;\r
+  EFI_KEY_DATA            KeyData;\r
   UINTN                   Size;\r
   EFI_STATUS              Status;\r
   BOOLEAN                 NoDisplay;\r
   UINTN                   Size;\r
   EFI_STATUS              Status;\r
   BOOLEAN                 NoDisplay;\r
@@ -174,15 +178,25 @@ InputBarRefresh (
   // wait for user input\r
   //\r
   for (;;) {\r
   // wait for user input\r
   //\r
   for (;;) {\r
-    gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
-    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+    Status = gBS->WaitForEvent (1, &mTextInEx->WaitForKeyEx, &EventIndex);\r
+    if (EFI_ERROR (Status) || (EventIndex != 0)) {\r
+      continue;\r
+    }\r
+    Status = mTextInEx->ReadKeyStrokeEx (mTextInEx, &KeyData);\r
     if (EFI_ERROR (Status)) {\r
       continue;\r
     }\r
     if (EFI_ERROR (Status)) {\r
       continue;\r
     }\r
+    if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) &&\r
+        (KeyData.KeyState.KeyShiftState != EFI_SHIFT_STATE_VALID)) {\r
+      //\r
+      // Shift key pressed.\r
+      //\r
+      continue;\r
+    }\r
     //\r
     // pressed ESC\r
     //\r
     //\r
     // pressed ESC\r
     //\r
-    if (Key.ScanCode == SCAN_ESC) {\r
+    if (KeyData.Key.ScanCode == SCAN_ESC) {\r
       Size    = 0;\r
       Status  = EFI_NOT_READY;\r
       break;\r
       Size    = 0;\r
       Status  = EFI_NOT_READY;\r
       break;\r
@@ -190,9 +204,9 @@ InputBarRefresh (
     //\r
     // return pressed\r
     //\r
     //\r
     // return pressed\r
     //\r
-    if (Key.UnicodeChar == CHAR_LINEFEED || Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
+    if (KeyData.Key.UnicodeChar == CHAR_LINEFEED || KeyData.Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
       break;\r
       break;\r
-    } else if (Key.UnicodeChar == CHAR_BACKSPACE) {\r
+    } else if (KeyData.Key.UnicodeChar == CHAR_BACKSPACE) {\r
       //\r
       // backspace\r
       //\r
       //\r
       // backspace\r
       //\r
@@ -205,11 +219,11 @@ InputBarRefresh (
 \r
         }\r
       }\r
 \r
         }\r
       }\r
-    } else if (Key.UnicodeChar <= 127 && Key.UnicodeChar >= 32) {\r
+    } else if (KeyData.Key.UnicodeChar <= 127 && KeyData.Key.UnicodeChar >= 32) {\r
       //\r
       // VALID ASCII char pressed\r
       //\r
       //\r
       // VALID ASCII char pressed\r
       //\r
-      mReturnString[Size] = Key.UnicodeChar;\r
+      mReturnString[Size] = KeyData.Key.UnicodeChar;\r
 \r
       //\r
       // should be less than specified length\r
 \r
       //\r
       // should be less than specified length\r
index f4aaee9ac5adb32d48ac28a9c6db31ce09cfbd9d..e7e6c786804578a12561afbacbef6d30f8b1d29d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Declares imputbar interface functions.\r
 \r
 /** @file\r
   Declares imputbar interface functions.\r
 \r
-  Copyright (c) 2005 - 2011, 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
 \r
 /**\r
   Initialize the input bar.\r
 \r
 /**\r
   Initialize the input bar.\r
+\r
+  @param[in] TextInEx  Pointer to SimpleTextInEx instance in System Table.\r
 **/\r
 VOID\r
 InputBarInit (\r
 **/\r
 VOID\r
 InputBarInit (\r
-  VOID\r
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx\r
   );\r
 \r
 /**\r
   );\r
 \r
 /**\r
index 2e00b90c6b4d4c9236638f0b26d712f19ea9ab60..b86594bb283e146cd1063a6ee632e34321777416 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   implements menubar interface functions.\r
 \r
 /** @file\r
   implements menubar interface functions.\r
 \r
-  Copyright (c) 2005 - 2011, 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
@@ -165,7 +165,7 @@ MenuBarDispatchFunctionKey (
 /**\r
   Function to dispatch the correct function based on a control-based key (ctrl+o...)\r
 \r
 /**\r
   Function to dispatch the correct function based on a control-based key (ctrl+o...)\r
 \r
-  @param[in] Key                The pressed key.\r
+  @param[in] KeyData                The pressed key.\r
 \r
   @retval EFI_NOT_FOUND         The key was not a valid control-based key \r
                                 (an error was sent to the status bar).\r
 \r
   @retval EFI_NOT_FOUND         The key was not a valid control-based key \r
                                 (an error was sent to the status bar).\r
@@ -173,17 +173,41 @@ MenuBarDispatchFunctionKey (
 **/\r
 EFI_STATUS\r
 MenuBarDispatchControlHotKey (\r
 **/\r
 EFI_STATUS\r
 MenuBarDispatchControlHotKey (\r
-  IN CONST EFI_INPUT_KEY   *Key\r
+  IN CONST EFI_KEY_DATA   *KeyData\r
   )\r
 {\r
   )\r
 {\r
-  \r
-  if ((SCAN_CONTROL_Z < Key->UnicodeChar)\r
-    ||(NULL == ControlBasedMenuFunctions[Key->UnicodeChar]))\r
+  UINT16                  ControlIndex;\r
+\r
+  //\r
+  // Set to invalid value first.\r
+  //\r
+  ControlIndex = MAX_UINT16;\r
+\r
+  if ((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) {\r
+    //\r
+    // For those console devices that cannot report the CONTROL state,\r
+    // Ctrl+A is translated to 1 (UnicodeChar).\r
+    //\r
+    ControlIndex = KeyData->Key.UnicodeChar;\r
+  } else if (((KeyData->KeyState.KeyShiftState & (EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED)) != 0) &&\r
+             ((KeyData->KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID | EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED)) == 0)) {\r
+    //\r
+    // For those console devices that can report the CONTROL state,\r
+    // make sure only CONTROL is pressed.\r
+    //\r
+    if ((KeyData->Key.UnicodeChar >= L'A') && (KeyData->Key.UnicodeChar <= L'Z')) {\r
+      ControlIndex = KeyData->Key.UnicodeChar - L'A' + 1;\r
+    } else if ((KeyData->Key.UnicodeChar >= L'a') && (KeyData->Key.UnicodeChar <= L'z')) {\r
+      ControlIndex = KeyData->Key.UnicodeChar - L'a' + 1;\r
+    }\r
+  }\r
+  if ((SCAN_CONTROL_Z < ControlIndex)\r
+    ||(NULL == ControlBasedMenuFunctions[ControlIndex]))\r
   {\r
       return EFI_NOT_FOUND;\r
   }\r
 \r
   {\r
       return EFI_NOT_FOUND;\r
   }\r
 \r
-  ControlBasedMenuFunctions[Key->UnicodeChar]();\r
+  ControlBasedMenuFunctions[ControlIndex]();\r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
index d545db93465b1e9f49019b7699b09ccd7b44a24d..a15617edf6fb4f0889edcf25e27da934f32df668 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Declares menubar interface functions.\r
 \r
 /** @file\r
   Declares menubar interface functions.\r
 \r
-  Copyright (c) 2005 - 2011, 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
@@ -105,7 +105,7 @@ MenuBarDispatchFunctionKey (
 /**\r
   Function to dispatch the correct function based on a control-based key (ctrl+o...)\r
 \r
 /**\r
   Function to dispatch the correct function based on a control-based key (ctrl+o...)\r
 \r
-  @param[in] Key                The pressed key.\r
+  @param[in] KeyData                The pressed key.\r
 \r
   @retval EFI_NOT_FOUND         The key was not a valid control-based key \r
                                 (an error was sent to the status bar).\r
 \r
   @retval EFI_NOT_FOUND         The key was not a valid control-based key \r
                                 (an error was sent to the status bar).\r
@@ -113,7 +113,7 @@ MenuBarDispatchFunctionKey (
 **/\r
 EFI_STATUS\r
 MenuBarDispatchControlHotKey (\r
 **/\r
 EFI_STATUS\r
 MenuBarDispatchControlHotKey (\r
-  IN CONST EFI_INPUT_KEY   *Key\r
+  IN CONST EFI_KEY_DATA   *KeyData\r
   );\r
 \r
 #endif\r
   );\r
 \r
 #endif\r
index 8f0da3b6673b007520f087e664540e816d8356d2..2a0429a4a1bc7c913b7dd8d42dbf0a7f35cef8a5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   data types that are used by editor\r
   \r
 /** @file\r
   data types that are used by editor\r
   \r
-  Copyright (c) 2005 - 2017, 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
@@ -109,17 +109,18 @@ typedef struct {
 } HEFI_EDITOR_BUFFER_IMAGE;\r
 \r
 typedef struct {\r
 } HEFI_EDITOR_BUFFER_IMAGE;\r
 \r
 typedef struct {\r
-  HEFI_EDITOR_BUFFER_IMAGE    *BufferImage;\r
-\r
-  HEFI_EDITOR_COLOR_UNION     ColorAttributes;\r
-  HEFI_EDITOR_POSITION        ScreenSize;           // row number and column number\r
-  BOOLEAN                     MouseSupported;\r
-  EFI_SIMPLE_POINTER_PROTOCOL *MouseInterface;\r
-  INT32                       MouseAccumulatorX;\r
-  INT32                       MouseAccumulatorY;\r
-\r
-  UINTN                       SelectStart;          // starting from 1\r
-  UINTN                       SelectEnd;            // starting from 1\r
+  HEFI_EDITOR_BUFFER_IMAGE          *BufferImage;\r
+\r
+  HEFI_EDITOR_COLOR_UNION           ColorAttributes;\r
+  HEFI_EDITOR_POSITION              ScreenSize;           // row number and column number\r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInputEx;\r
+  BOOLEAN                           MouseSupported;\r
+  EFI_SIMPLE_POINTER_PROTOCOL       *MouseInterface;\r
+  INT32                             MouseAccumulatorX;\r
+  INT32                             MouseAccumulatorY;\r
+\r
+  UINTN                             SelectStart;          // starting from 1\r
+  UINTN                             SelectEnd;            // starting from 1\r
 } HEFI_EDITOR_GLOBAL_EDITOR;\r
 \r
 #endif\r
 } HEFI_EDITOR_GLOBAL_EDITOR;\r
 \r
 #endif\r
index 491acb131ea16d28acae2465287780ff9110b9ec..065f8e95a706673e0693e6fb0ae67ccf861bf9b9 100644 (file)
@@ -4,7 +4,7 @@
      - Instances of the other objects of the editor\r
      - Main Interfaces\r
   \r
      - Instances of the other objects of the editor\r
      - Main Interfaces\r
   \r
-  Copyright (c) 2005 - 2012, 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
@@ -56,6 +56,7 @@ HEFI_EDITOR_GLOBAL_EDITOR       HMainEditorConst = {
     0,\r
     0\r
   },\r
     0,\r
     0\r
   },\r
+  NULL,\r
   FALSE,\r
   NULL,\r
   0,\r
   FALSE,\r
   NULL,\r
   0,\r
@@ -105,22 +106,53 @@ HMainCommandDisplayHelp (
   VOID\r
   )\r
 {\r
   VOID\r
   )\r
 {\r
-  INT32    CurrentLine;\r
-  CHAR16 * InfoString;\r
-  EFI_INPUT_KEY  Key;\r
-\r
-  CurrentLine = 0;\r
+  INT32           CurrentLine;\r
+  CHAR16          *InfoString;\r
+  EFI_KEY_DATA    KeyData;\r
+  EFI_STATUS      Status;\r
+  UINTN           EventIndex;\r
+  \r
+  //\r
   // print helpInfo      \r
   // print helpInfo      \r
+  //\r
   for (CurrentLine = 0; 0 != HexMainMenuHelpInfo[CurrentLine]; CurrentLine++) {\r
     InfoString = HiiGetString(gShellDebug1HiiHandle, HexMainMenuHelpInfo[CurrentLine]\r
 , NULL);\r
     ShellPrintEx (0,CurrentLine+1,L"%E%s%N",InfoString);        \r
   }\r
   for (CurrentLine = 0; 0 != HexMainMenuHelpInfo[CurrentLine]; CurrentLine++) {\r
     InfoString = HiiGetString(gShellDebug1HiiHandle, HexMainMenuHelpInfo[CurrentLine]\r
 , NULL);\r
     ShellPrintEx (0,CurrentLine+1,L"%E%s%N",InfoString);        \r
   }\r
-  \r
+\r
+  //\r
   // scan for ctrl+w\r
   // scan for ctrl+w\r
-  do {\r
-    gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-  } while(SCAN_CONTROL_W != Key.UnicodeChar); \r
+  //\r
+  while (TRUE) {\r
+    Status = gBS->WaitForEvent (1, &HMainEditor.TextInputEx->WaitForKeyEx, &EventIndex);\r
+    if (EFI_ERROR (Status) || (EventIndex != 0)) {\r
+      continue;\r
+    }\r
+    Status = HMainEditor.TextInputEx->ReadKeyStrokeEx (HMainEditor.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 buffer's info\r
   HBufferImageNeedRefresh = TRUE;\r
 \r
   // update screen with buffer's info\r
   HBufferImageNeedRefresh = TRUE;\r
@@ -1633,6 +1665,19 @@ HMainEditorInit (
         &(HMainEditor.ScreenSize.Row)\r
         );\r
 \r
         &(HMainEditor.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**)&HMainEditor.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
@@ -1706,7 +1751,7 @@ HMainEditorInit (
     return EFI_LOAD_ERROR;\r
   }\r
 \r
     return EFI_LOAD_ERROR;\r
   }\r
 \r
-  InputBarInit ();\r
+  InputBarInit (HMainEditor.TextInputEx);\r
 \r
   Status = HBufferImageInit ();\r
   if (EFI_ERROR (Status)) {\r
 \r
   Status = HBufferImageInit ();\r
   if (EFI_ERROR (Status)) {\r
@@ -2058,9 +2103,11 @@ HMainEditorKeyInput (
   VOID\r
   )\r
 {\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
   BOOLEAN                   LengthChange;\r
   UINTN                     Size;\r
   UINTN                     OldSize;\r
   BOOLEAN                   LengthChange;\r
   UINTN                     Size;\r
   UINTN                     OldSize;\r
@@ -2219,84 +2266,94 @@ HMainEditorKeyInput (
       }\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
-      HBufferImageMouseNeedRefresh = TRUE;\r
-\r
-      //\r
-      // clear previous status string\r
-      //\r
-      StatusBarSetRefresh();\r
-      if (EFI_SUCCESS == MenuBarDispatchControlHotKey(&Key)) {\r
-        Status = EFI_SUCCESS;\r
-      } else if (Key.ScanCode == SCAN_NULL) {\r
-        Status = HBufferImageHandleInput (&Key);\r
-      } else if (((Key.ScanCode >= SCAN_UP) && (Key.ScanCode <= SCAN_PAGE_DOWN))) {\r
-        Status = HBufferImageHandleInput (&Key);\r
-      } else if (((Key.ScanCode >= SCAN_F1) && Key.ScanCode <= (SCAN_F12))) {\r
-        Status = MenuBarDispatchFunctionKey (&Key);\r
-      } else {\r
-        StatusBarSetStatusString (L"Unknown Command");\r
-\r
-        HBufferImageMouseNeedRefresh = FALSE;\r
-      }\r
+    Status = gBS->WaitForEvent (1, &HMainEditor.TextInputEx->WaitForKeyEx, &EventIndex);\r
+    if (!EFI_ERROR (Status) && EventIndex == 0) {\r
+      Status = HMainEditor.TextInputEx->ReadKeyStrokeEx (HMainEditor.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
+        HBufferImageMouseNeedRefresh = TRUE;\r
 \r
 \r
-      if (Status != EFI_SUCCESS && Status != EFI_OUT_OF_RESOURCES) {\r
         //\r
         //\r
-        // not already has some error status\r
+        // clear previous status string\r
         //\r
         //\r
-        if (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_SUCCESS == MenuBarDispatchControlHotKey(&KeyData)) {\r
+          Status = EFI_SUCCESS;\r
+        } else if (NoShiftState && KeyData.Key.ScanCode == SCAN_NULL) {\r
+          Status = HBufferImageHandleInput (&KeyData.Key);\r
+        } else if (NoShiftState && ((KeyData.Key.ScanCode >= SCAN_UP) && (KeyData.Key.ScanCode <= SCAN_PAGE_DOWN))) {\r
+          Status = HBufferImageHandleInput (&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
+\r
+          HBufferImageMouseNeedRefresh = FALSE;\r
+        }\r
+\r
+        if (Status != EFI_SUCCESS && Status != EFI_OUT_OF_RESOURCES) {\r
+          //\r
+          // not already has some error status\r
+          //\r
+          if (StrCmp (L"", StatusBarGetString()) == 0) {\r
+            StatusBarSetStatusString (L"Disk Error. Try Again");\r
+          }\r
         }\r
       }\r
         }\r
       }\r
-    }\r
-    //\r
-    // decide if has to set length warning\r
-    //\r
-    if (HBufferImage.BufferType != HBufferImageBackupVar.BufferType) {\r
-      LengthChange = FALSE;\r
-    } else {\r
       //\r
       //\r
-      // still the old buffer\r
+      // decide if has to set length warning\r
       //\r
       //\r
-      if (HBufferImage.BufferType != FileTypeFileBuffer) {\r
-        Size = HBufferImageGetTotalSize ();\r
+      if (HBufferImage.BufferType != HBufferImageBackupVar.BufferType) {\r
+        LengthChange = FALSE;\r
+      } else {\r
+        //\r
+        // still the old buffer\r
+        //\r
+        if (HBufferImage.BufferType != FileTypeFileBuffer) {\r
+          Size = HBufferImageGetTotalSize ();\r
 \r
 \r
-        switch (HBufferImage.BufferType) {\r
-        case FileTypeDiskBuffer:\r
-          OldSize = HBufferImage.DiskImage->Size * HBufferImage.DiskImage->BlockSize;\r
-          break;\r
+          switch (HBufferImage.BufferType) {\r
+          case FileTypeDiskBuffer:\r
+            OldSize = HBufferImage.DiskImage->Size * HBufferImage.DiskImage->BlockSize;\r
+            break;\r
 \r
 \r
-        case FileTypeMemBuffer:\r
-          OldSize = HBufferImage.MemImage->Size;\r
-          break;\r
+          case FileTypeMemBuffer:\r
+            OldSize = HBufferImage.MemImage->Size;\r
+            break;\r
         \r
         \r
-        default:\r
-          OldSize = 0;\r
-          break;\r
-        }\r
+          default:\r
+            OldSize = 0;\r
+            break;\r
+          }\r
 \r
 \r
-        if (!LengthChange) {\r
-          if (OldSize != Size) {\r
-            StatusBarSetStatusString (L"Disk/Mem Buffer Length should not be changed");\r
+          if (!LengthChange) {\r
+            if (OldSize != Size) {\r
+              StatusBarSetStatusString (L"Disk/Mem Buffer Length should not be changed");\r
+            }\r
           }\r
           }\r
-        }\r
 \r
 \r
-        if (OldSize != Size) {\r
-          LengthChange = TRUE;\r
-        } else {\r
-          LengthChange = FALSE;\r
+          if (OldSize != Size) {\r
+            LengthChange = TRUE;\r
+          } else {\r
+            LengthChange = FALSE;\r
+          }\r
         }\r
       }\r
         }\r
       }\r
+      //\r
+      // after handling, refresh editor\r
+      //\r
+      HMainEditorRefresh ();\r
     }\r
     }\r
-    //\r
-    // after handling, refresh editor\r
-    //\r
-    HMainEditorRefresh ();\r
 \r
   } while (Status != EFI_OUT_OF_RESOURCES && !HEditorExit);\r
 \r
 \r
   } while (Status != EFI_OUT_OF_RESOURCES && !HEditorExit);\r
 \r