]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c
ShellPkg/[hex]edit: use SimpleTextInEx to read console
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / EditInputBar.c
index 978ce7f13a1f403c7cde1dcd4368fb26696f5d3c..6c6fc70bab4aee1ead43a7603ec59b1bf8d7bc44 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implements inputbar 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
 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
+  @param[in] TextInEx  Pointer to SimpleTextInEx instance in System Table.\r
 **/\r
 VOID\r
-EFIAPI\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
+  mTextInEx     = TextInEx;\r
 }\r
 \r
 /**\r
   Cleanup function for input bar.\r
 **/\r
 VOID\r
-EFIAPI\r
 InputBarCleanup (\r
   VOID\r
   )\r
@@ -59,7 +61,6 @@ InputBarCleanup (
   @param[in]  LastRow      The last printable row.\r
 **/\r
 VOID\r
-EFIAPI\r
 InputBarPrintInput (\r
   IN UINTN LastColumn,\r
   IN UINTN LastRow\r
@@ -103,7 +104,7 @@ InputBarPrintInput (
 \r
 typedef struct {\r
   UINT32  Foreground : 4;\r
-  UINT32  Background : 4;\r
+  UINT32  Background : 3;\r
 } INPUT_BAR_COLOR_ATTRIBUTES;\r
 \r
 typedef union {\r
@@ -121,7 +122,6 @@ typedef union {
   @retval EFI_SUCCESS           The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InputBarRefresh (\r
   UINTN LastRow,\r
   UINTN LastColumn\r
@@ -129,12 +129,10 @@ InputBarRefresh (
 {\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                   Limit;\r
-  UINTN                   mPromptLen;\r
   UINTN                   EventIndex;\r
   UINTN                   CursorRow;\r
   UINTN                   CursorCol;\r
@@ -151,10 +149,11 @@ InputBarRefresh (
   CursorCol             = gST->ConOut->Mode->CursorColumn;\r
   CursorRow             = gST->ConOut->Mode->CursorRow;\r
   Orig.Data             = gST->ConOut->Mode->Attribute;\r
-  New.Colors.Foreground = Orig.Colors.Background;\r
-  New.Colors.Background = Orig.Colors.Foreground;\r
+  New.Data              = 0;\r
+  New.Colors.Foreground = Orig.Colors.Background & 0xF;\r
+  New.Colors.Background = Orig.Colors.Foreground & 0x7;\r
 \r
-  gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r
+  gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r
 \r
   //\r
   // clear input bar\r
@@ -164,12 +163,6 @@ InputBarRefresh (
   gST->ConOut->SetCursorPosition (gST->ConOut, 0, LastRow - 1);\r
   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_LIBINPUTBAR_MAININPUTBAR), gShellDebug1HiiHandle, mPrompt);\r
 \r
-  //\r
-  // that's the maximum input length that can be displayed on screen\r
-  //\r
-  mPromptLen = StrLen (mPrompt);\r
-  Limit     = LastColumn - mPromptLen;\r
-\r
   //\r
   // this is a selection mPrompt, cursor will stay in edit area\r
   // actually this is for search , search/replace\r
@@ -185,15 +178,25 @@ InputBarRefresh (
   // 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 (((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
-    if (Key.ScanCode == SCAN_ESC) {\r
+    if (KeyData.Key.ScanCode == SCAN_ESC) {\r
       Size    = 0;\r
       Status  = EFI_NOT_READY;\r
       break;\r
@@ -201,9 +204,9 @@ InputBarRefresh (
     //\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
-    } else if (Key.UnicodeChar == CHAR_BACKSPACE) {\r
+    } else if (KeyData.Key.UnicodeChar == CHAR_BACKSPACE) {\r
       //\r
       // backspace\r
       //\r
@@ -216,11 +219,11 @@ InputBarRefresh (
 \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
-      mReturnString[Size] = Key.UnicodeChar;\r
+      mReturnString[Size] = KeyData.Key.UnicodeChar;\r
 \r
       //\r
       // should be less than specified length\r
@@ -268,7 +271,6 @@ InputBarRefresh (
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InputBarSetPrompt (\r
   IN CONST CHAR16 *Str\r
   )\r
@@ -295,7 +297,6 @@ InputBarSetPrompt (
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InputBarSetStringSize (\r
   UINTN   Size\r
   )\r
@@ -321,7 +322,6 @@ InputBarSetStringSize (
   @return The string that was input.\r
 **/\r
 CONST CHAR16*\r
-EFIAPI\r
 InputBarGetString (\r
   VOID\r
   )\r