From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AF1B2222DE127 for ; Mon, 12 Feb 2018 08:57:30 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2018 09:03:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,503,1511856000"; d="scan'208";a="26710915" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by FMSMGA003.fm.intel.com with ESMTP; 12 Feb 2018 09:03:19 -0800 Received: from fmsmsx101.amr.corp.intel.com (10.18.124.199) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 12 Feb 2018 09:03:18 -0800 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.47]) by fmsmsx101.amr.corp.intel.com ([169.254.1.39]) with mapi id 14.03.0319.002; Mon, 12 Feb 2018 09:03:18 -0800 From: "Carsey, Jaben" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" CC: Felix Thread-Topic: [PATCH] ShellPkg/[hex]edit: use SimpleTextInEx to read console Thread-Index: AQHTpBbcpR3OH5vjEkCoWzAE6ga/F6Og/pDQ Date: Mon, 12 Feb 2018 17:03:18 +0000 Message-ID: References: <20180212153330.21112-1-ruiyu.ni@intel.com> In-Reply-To: <20180212153330.21112-1-ruiyu.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMGUzNGI3NTItZTFmZS00ZGViLWIyZTktNGQwYmRlNGIxM2QwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IjhDaytMZEFRWVRuaDA5WXVQbjMwT0hiSTQ1VjdJcjN5MU9HUTBwbWpXcjA9In0= x-ctpclassification: CTP_NT x-originating-ip: [10.1.200.107] MIME-Version: 1.0 Subject: Re: [PATCH] ShellPkg/[hex]edit: use SimpleTextInEx to read console X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Feb 2018 16:57:31 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jaben Carsey > -----Original Message----- > From: Ni, Ruiyu > Sent: Monday, February 12, 2018 7:34 AM > To: edk2-devel@lists.01.org > Cc: Felix ; Carsey, Jaben > Subject: [PATCH] ShellPkg/[hex]edit: use SimpleTextInEx to read console > Importance: High >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D682 >=20 > Edit and HexEdit commands assume that SimpleTxtIn translates > Ctrl+ key combinations into Unicode control characters > (0x1-0x1A). >=20 > 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+ key > combinations. >=20 > The patch changes edit and hexedit to only consumes SimpleTextInEx. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ruiyu Ni > Reported-by: Felix > Cc: Felix > Cc: Jaben Carsey > --- > .../Edit/MainTextEditor.c | 135 +++++++++----- > .../Edit/TextEditorTypes.h | 21 ++- > .../UefiShellDebug1CommandsLib/EditInputBar.c | 34 +++- > .../UefiShellDebug1CommandsLib/EditInputBar.h | 6 +- > .../UefiShellDebug1CommandsLib/EditMenuBar.c | 38 +++- > .../UefiShellDebug1CommandsLib/EditMenuBar.h | 6 +- > .../HexEdit/HexEditorTypes.h | 25 +-- > .../HexEdit/MainHexEditor.c | 205 +++++++++++++--= ------ > 8 files changed, 309 insertions(+), 161 deletions(-) >=20 > diff --git > a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c > b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c > index 14f51dff19..a197f80a40 100644 > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c > +++ > b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c > @@ -1,7 +1,7 @@ > /** @file > Implements editor interface functions. >=20 > - Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved. > + Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -1362,7 +1362,9 @@ MainCommandDisplayHelp ( > { > INT32 CurrentLine; > CHAR16 *InfoString; > - EFI_INPUT_KEY Key; > + EFI_KEY_DATA KeyData; > + EFI_STATUS Status; > + UINTN EventIndex; >=20 > // > // print helpInfo > @@ -1371,14 +1373,39 @@ MainCommandDisplayHelp ( > InfoString =3D HiiGetString(gShellDebug1HiiHandle, > MainMenuHelpInfo[CurrentLine], NULL); > ShellPrintEx (0, CurrentLine+1, L"%E%s%N", InfoString); > } > - > + > // > // scan for ctrl+w > // > - do { > - gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); > - } while(SCAN_CONTROL_W !=3D Key.UnicodeChar); > + while (TRUE) { > + Status =3D gBS->WaitForEvent (1, &MainEditor.TextInputEx->WaitForKey= Ex, > &EventIndex); > + if (EFI_ERROR (Status) || (EventIndex !=3D 0)) { > + continue; > + } > + Status =3D MainEditor.TextInputEx->ReadKeyStrokeEx > (MainEditor.TextInputEx, &KeyData); > + if (EFI_ERROR (Status)) { > + continue; > + } >=20 > + if ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) =3D=3D = 0) { > + // > + // For consoles that don't support shift state reporting, > + // CTRL+W is translated to L'W' - L'A' + 1. > + // > + if (KeyData.Key.UnicodeChar =3D=3D L'W' - L'A' + 1) { > + break; > + } > + } else if (((KeyData.KeyState.KeyShiftState & > (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) !=3D 0) && > + ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALI= D | > EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) =3D=3D 0)) { > + // > + // For consoles that supports shift state reporting, > + // make sure that only CONTROL shift key is pressed. > + // > + if ((KeyData.Key.UnicodeChar =3D=3D 'w') || (KeyData.Key.UnicodeCh= ar =3D=3D > 'W')) { > + break; > + } > + } > + } > // > // update screen with file buffer's info > // > @@ -1407,6 +1434,7 @@ EFI_EDITOR_GLOBAL_EDITOR MainEditorConst =3D > { > 0 > }, > NULL, > + NULL, > FALSE, > NULL > }; > @@ -1452,6 +1480,19 @@ MainEditorInit ( > &(MainEditor.ScreenSize.Row) > ); >=20 > + // > + // Find TextInEx in System Table ConsoleInHandle > + // Per UEFI Spec, TextInEx is required for a console capable platform. > + // > + Status =3D gBS->HandleProtocol ( > + gST->ConsoleInHandle, > + &gEfiSimpleTextInputExProtocolGuid, > + (VOID**)&MainEditor.TextInputEx > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > // > // Find mouse in System Table ConsoleInHandle > // > @@ -1521,7 +1562,7 @@ MainEditorInit ( > return EFI_LOAD_ERROR; > } >=20 > - InputBarInit (); > + InputBarInit (MainEditor.TextInputEx); >=20 > Status =3D FileBufferInit (); > if (EFI_ERROR (Status)) { > @@ -1794,9 +1835,11 @@ MainEditorKeyInput ( > VOID > ) > { > - EFI_INPUT_KEY Key; > + EFI_KEY_DATA KeyData; > EFI_STATUS Status; > EFI_SIMPLE_POINTER_STATE MouseState; > + UINTN EventIndex; > + BOOLEAN NoShiftState; >=20 > do { >=20 > @@ -1831,46 +1874,52 @@ MainEditorKeyInput ( > } > } >=20 > - Status =3D gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); > - if (!EFI_ERROR (Status)) { > - // > - // dispatch to different components' key handling function > - // so not everywhere has to set this variable > - // > - FileBufferMouseNeedRefresh =3D TRUE; > - // > - // clear previous status string > - // > - StatusBarSetRefresh(); > - > - // > - // dispatch to different components' key handling function > - // > - if (EFI_NOT_FOUND !=3D MenuBarDispatchControlHotKey(&Key)) { > - Status =3D EFI_SUCCESS; > - } else if ((Key.ScanCode =3D=3D SCAN_NULL) || ((Key.ScanCode >=3D > SCAN_UP) && (Key.ScanCode <=3D SCAN_PAGE_DOWN))) { > - Status =3D FileBufferHandleInput (&Key); > - } else if ((Key.ScanCode >=3D SCAN_F1) && (Key.ScanCode <=3D SCAN_= F12)) > { > - Status =3D MenuBarDispatchFunctionKey (&Key); > - } else { > - StatusBarSetStatusString (L"Unknown Command"); > - FileBufferMouseNeedRefresh =3D FALSE; > - } > - > - if (Status !=3D EFI_SUCCESS && Status !=3D EFI_OUT_OF_RESOURCES) { > + Status =3D gBS->WaitForEvent (1, &MainEditor.TextInputEx->WaitForKey= Ex, > &EventIndex); > + if (!EFI_ERROR (Status) && EventIndex =3D=3D 0) { > + Status =3D MainEditor.TextInputEx->ReadKeyStrokeEx > (MainEditor.TextInputEx, &KeyData); > + if (!EFI_ERROR (Status)) { > + // > + // dispatch to different components' key handling function > + // so not everywhere has to set this variable > + // > + FileBufferMouseNeedRefresh =3D TRUE; > // > - // not already has some error status > + // clear previous status string > // > - if (StatusBarGetString() !=3D NULL && StrCmp (L"", StatusBarGetS= tring()) > =3D=3D 0) { > - StatusBarSetStatusString (L"Disk Error. Try Again"); > + StatusBarSetRefresh(); > + // > + // NoShiftState: TRUE when no shift key is pressed. > + // > + NoShiftState =3D ((KeyData.KeyState.KeyShiftState & > EFI_SHIFT_STATE_VALID) =3D=3D 0) || (KeyData.KeyState.KeyShiftState =3D= =3D > EFI_SHIFT_STATE_VALID); > + // > + // dispatch to different components' key handling function > + // > + if (EFI_NOT_FOUND !=3D MenuBarDispatchControlHotKey(&KeyData)) { > + Status =3D EFI_SUCCESS; > + } else if (NoShiftState && ((KeyData.Key.ScanCode =3D=3D SCAN_NU= LL) || > ((KeyData.Key.ScanCode >=3D SCAN_UP) && (KeyData.Key.ScanCode <=3D > SCAN_PAGE_DOWN)))) { > + Status =3D FileBufferHandleInput (&KeyData.Key); > + } else if (NoShiftState && (KeyData.Key.ScanCode >=3D SCAN_F1) &= & > (KeyData.Key.ScanCode <=3D SCAN_F12)) { > + Status =3D MenuBarDispatchFunctionKey (&KeyData.Key); > + } else { > + StatusBarSetStatusString (L"Unknown Command"); > + FileBufferMouseNeedRefresh =3D FALSE; > + } > + > + if (Status !=3D EFI_SUCCESS && Status !=3D EFI_OUT_OF_RESOURCES)= { > + // > + // not already has some error status > + // > + if (StatusBarGetString() !=3D NULL && StrCmp (L"", StatusBarGe= tString()) > =3D=3D 0) { > + StatusBarSetStatusString (L"Disk Error. Try Again"); > + } > } > - } >=20 > + } > + // > + // after handling, refresh editor > + // > + MainEditorRefresh (); > } > - // > - // after handling, refresh editor > - // > - MainEditorRefresh (); >=20 > } while (Status !=3D EFI_OUT_OF_RESOURCES && !EditorExit); >=20 > diff --git > a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditorTypes.h > b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditorTypes.h > index dfd56dd9a6..4cabba7b13 100644 > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditorTypes.h > +++ > b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditorTypes.h > @@ -1,7 +1,7 @@ > /** @file > Declares editor types. >=20 > - Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. > + Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -87,15 +87,16 @@ typedef struct { > } EFI_EDITOR_FILE_BUFFER; >=20 > typedef struct { > - EFI_EDITOR_FILE_BUFFER *FileBuffer; > - > - EFI_EDITOR_COLOR_UNION ColorAttributes; > - EFI_EDITOR_POSITION ScreenSize; // row number and column numbe= r > - EFI_EDITOR_LINE *CutLine; // clip board > - BOOLEAN MouseSupported; > - EFI_SIMPLE_POINTER_PROTOCOL *MouseInterface; > - INT32 MouseAccumulatorX; > - INT32 MouseAccumulatorY; > + EFI_EDITOR_FILE_BUFFER *FileBuffer; > + > + EFI_EDITOR_COLOR_UNION ColorAttributes; > + EFI_EDITOR_POSITION ScreenSize; // row number and column > number > + EFI_EDITOR_LINE *CutLine; // clip board > + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInputEx; > + BOOLEAN MouseSupported; > + EFI_SIMPLE_POINTER_PROTOCOL *MouseInterface; > + INT32 MouseAccumulatorX; > + INT32 MouseAccumulatorY; >=20 > } EFI_EDITOR_GLOBAL_EDITOR; >=20 > diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c > b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c > index 26f70d719a..6c6fc70bab 100644 > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c > +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c > @@ -1,7 +1,7 @@ > /** @file > Implements inputbar interface functions. >=20 > - Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. > + Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -18,18 +18,22 @@ > CHAR16 *mPrompt; // Input bar mPrompt string. > CHAR16 *mReturnString; // The returned string. > UINTN StringSize; // Size of mReturnString space size. > +EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *mTextInEx; >=20 > /** > Initialize the input bar. > + > + @param[in] TextInEx Pointer to SimpleTextInEx instance in System Tabl= e. > **/ > VOID > InputBarInit ( > - VOID > + IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx > ) > { > mPrompt =3D NULL; > mReturnString =3D NULL; > StringSize =3D 0; > + mTextInEx =3D TextInEx; > } >=20 > /** > @@ -125,7 +129,7 @@ InputBarRefresh ( > { > INPUT_BAR_COLOR_UNION Orig; > INPUT_BAR_COLOR_UNION New; > - EFI_INPUT_KEY Key; > + EFI_KEY_DATA KeyData; > UINTN Size; > EFI_STATUS Status; > BOOLEAN NoDisplay; > @@ -174,15 +178,25 @@ InputBarRefresh ( > // wait for user input > // > for (;;) { > - gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); > - Status =3D gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); > + Status =3D gBS->WaitForEvent (1, &mTextInEx->WaitForKeyEx, > &EventIndex); > + if (EFI_ERROR (Status) || (EventIndex !=3D 0)) { > + continue; > + } > + Status =3D mTextInEx->ReadKeyStrokeEx (mTextInEx, &KeyData); > if (EFI_ERROR (Status)) { > continue; > } > + if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) !=3D 0= ) && > + (KeyData.KeyState.KeyShiftState !=3D EFI_SHIFT_STATE_VALID)) { > + // > + // Shift key pressed. > + // > + continue; > + } > // > // pressed ESC > // > - if (Key.ScanCode =3D=3D SCAN_ESC) { > + if (KeyData.Key.ScanCode =3D=3D SCAN_ESC) { > Size =3D 0; > Status =3D EFI_NOT_READY; > break; > @@ -190,9 +204,9 @@ InputBarRefresh ( > // > // return pressed > // > - if (Key.UnicodeChar =3D=3D CHAR_LINEFEED || Key.UnicodeChar =3D=3D > CHAR_CARRIAGE_RETURN) { > + if (KeyData.Key.UnicodeChar =3D=3D CHAR_LINEFEED || > KeyData.Key.UnicodeChar =3D=3D CHAR_CARRIAGE_RETURN) { > break; > - } else if (Key.UnicodeChar =3D=3D CHAR_BACKSPACE) { > + } else if (KeyData.Key.UnicodeChar =3D=3D CHAR_BACKSPACE) { > // > // backspace > // > @@ -205,11 +219,11 @@ InputBarRefresh ( >=20 > } > } > - } else if (Key.UnicodeChar <=3D 127 && Key.UnicodeChar >=3D 32) { > + } else if (KeyData.Key.UnicodeChar <=3D 127 && KeyData.Key.UnicodeCh= ar > >=3D 32) { > // > // VALID ASCII char pressed > // > - mReturnString[Size] =3D Key.UnicodeChar; > + mReturnString[Size] =3D KeyData.Key.UnicodeChar; >=20 > // > // should be less than specified length > diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.h > b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.h > index f4aaee9ac5..e7e6c78680 100644 > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.h > +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.h > @@ -1,7 +1,7 @@ > /** @file > Declares imputbar interface functions. >=20 > - Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. > + Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -17,10 +17,12 @@ >=20 > /** > Initialize the input bar. > + > + @param[in] TextInEx Pointer to SimpleTextInEx instance in System Tabl= e. > **/ > VOID > InputBarInit ( > - VOID > + IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx > ); >=20 > /** > diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c > b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c > index 2e00b90c6b..b86594bb28 100644 > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c > +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c > @@ -1,7 +1,7 @@ > /** @file > implements menubar interface functions. >=20 > - Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. > + Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -165,7 +165,7 @@ MenuBarDispatchFunctionKey ( > /** > Function to dispatch the correct function based on a control-based key > (ctrl+o...) >=20 > - @param[in] Key The pressed key. > + @param[in] KeyData The pressed key. >=20 > @retval EFI_NOT_FOUND The key was not a valid control-based ke= y > (an error was sent to the status bar). > @@ -173,17 +173,41 @@ MenuBarDispatchFunctionKey ( > **/ > EFI_STATUS > MenuBarDispatchControlHotKey ( > - IN CONST EFI_INPUT_KEY *Key > + IN CONST EFI_KEY_DATA *KeyData > ) > { > - > - if ((SCAN_CONTROL_Z < Key->UnicodeChar) > - ||(NULL =3D=3D ControlBasedMenuFunctions[Key->UnicodeChar])) > + UINT16 ControlIndex; > + > + // > + // Set to invalid value first. > + // > + ControlIndex =3D MAX_UINT16; > + > + if ((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) =3D=3D 0= ) { > + // > + // For those console devices that cannot report the CONTROL state, > + // Ctrl+A is translated to 1 (UnicodeChar). > + // > + ControlIndex =3D KeyData->Key.UnicodeChar; > + } else if (((KeyData->KeyState.KeyShiftState & > (EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED)) !=3D 0) && > + ((KeyData->KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID= | > EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED)) =3D=3D 0)) { > + // > + // For those console devices that can report the CONTROL state, > + // make sure only CONTROL is pressed. > + // > + if ((KeyData->Key.UnicodeChar >=3D L'A') && (KeyData->Key.UnicodeCha= r > <=3D L'Z')) { > + ControlIndex =3D KeyData->Key.UnicodeChar - L'A' + 1; > + } else if ((KeyData->Key.UnicodeChar >=3D L'a') && (KeyData- > >Key.UnicodeChar <=3D L'z')) { > + ControlIndex =3D KeyData->Key.UnicodeChar - L'a' + 1; > + } > + } > + if ((SCAN_CONTROL_Z < ControlIndex) > + ||(NULL =3D=3D ControlBasedMenuFunctions[ControlIndex])) > { > return EFI_NOT_FOUND; > } >=20 > - ControlBasedMenuFunctions[Key->UnicodeChar](); > + ControlBasedMenuFunctions[ControlIndex](); > return EFI_SUCCESS; > } >=20 > diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.h > b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.h > index d545db9346..a15617edf6 100644 > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.h > +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.h > @@ -1,7 +1,7 @@ > /** @file > Declares menubar interface functions. >=20 > - Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. > + Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -105,7 +105,7 @@ MenuBarDispatchFunctionKey ( > /** > Function to dispatch the correct function based on a control-based key > (ctrl+o...) >=20 > - @param[in] Key The pressed key. > + @param[in] KeyData The pressed key. >=20 > @retval EFI_NOT_FOUND The key was not a valid control-based ke= y > (an error was sent to the status bar). > @@ -113,7 +113,7 @@ MenuBarDispatchFunctionKey ( > **/ > EFI_STATUS > MenuBarDispatchControlHotKey ( > - IN CONST EFI_INPUT_KEY *Key > + IN CONST EFI_KEY_DATA *KeyData > ); >=20 > #endif > diff --git > a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEditorTypes. > h > b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEditorTypes. > h > index 8f0da3b667..2a0429a4a1 100644 > --- > a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEditorTypes. > h > +++ > b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEditorTypes. > h > @@ -1,7 +1,7 @@ > /** @file > data types that are used by editor >=20 > - Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved. > + Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -109,17 +109,18 @@ typedef struct { > } HEFI_EDITOR_BUFFER_IMAGE; >=20 > typedef struct { > - HEFI_EDITOR_BUFFER_IMAGE *BufferImage; > - > - HEFI_EDITOR_COLOR_UNION ColorAttributes; > - HEFI_EDITOR_POSITION ScreenSize; // row number and co= lumn > number > - BOOLEAN MouseSupported; > - EFI_SIMPLE_POINTER_PROTOCOL *MouseInterface; > - INT32 MouseAccumulatorX; > - INT32 MouseAccumulatorY; > - > - UINTN SelectStart; // starting from 1 > - UINTN SelectEnd; // starting from 1 > + HEFI_EDITOR_BUFFER_IMAGE *BufferImage; > + > + HEFI_EDITOR_COLOR_UNION ColorAttributes; > + HEFI_EDITOR_POSITION ScreenSize; // row number = and > column number > + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInputEx; > + BOOLEAN MouseSupported; > + EFI_SIMPLE_POINTER_PROTOCOL *MouseInterface; > + INT32 MouseAccumulatorX; > + INT32 MouseAccumulatorY; > + > + UINTN SelectStart; // starting fr= om 1 > + UINTN SelectEnd; // starting fr= om 1 > } HEFI_EDITOR_GLOBAL_EDITOR; >=20 > #endif > diff --git > a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c > b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c > index 491acb131e..065f8e95a7 100644 > --- > a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c > +++ > b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c > @@ -4,7 +4,7 @@ > - Instances of the other objects of the editor > - Main Interfaces >=20 > - Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved. > + Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -56,6 +56,7 @@ HEFI_EDITOR_GLOBAL_EDITOR HMainEditorConst =3D { > 0, > 0 > }, > + NULL, > FALSE, > NULL, > 0, > @@ -105,22 +106,53 @@ HMainCommandDisplayHelp ( > VOID > ) > { > - INT32 CurrentLine; > - CHAR16 * InfoString; > - EFI_INPUT_KEY Key; > - > - CurrentLine =3D 0; > + INT32 CurrentLine; > + CHAR16 *InfoString; > + EFI_KEY_DATA KeyData; > + EFI_STATUS Status; > + UINTN EventIndex; > + > + // > // print helpInfo > + // > for (CurrentLine =3D 0; 0 !=3D HexMainMenuHelpInfo[CurrentLine]; > CurrentLine++) { > InfoString =3D HiiGetString(gShellDebug1HiiHandle, > HexMainMenuHelpInfo[CurrentLine] > , NULL); > ShellPrintEx (0,CurrentLine+1,L"%E%s%N",InfoString); > } > - > + > + // > // scan for ctrl+w > - do { > - gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); > - } while(SCAN_CONTROL_W !=3D Key.UnicodeChar); > + // > + while (TRUE) { > + Status =3D gBS->WaitForEvent (1, &HMainEditor.TextInputEx- > >WaitForKeyEx, &EventIndex); > + if (EFI_ERROR (Status) || (EventIndex !=3D 0)) { > + continue; > + } > + Status =3D HMainEditor.TextInputEx->ReadKeyStrokeEx > (HMainEditor.TextInputEx, &KeyData); > + if (EFI_ERROR (Status)) { > + continue; > + } > + > + if ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) =3D=3D = 0) { > + // > + // For consoles that don't support shift state reporting, > + // CTRL+W is translated to L'W' - L'A' + 1. > + // > + if (KeyData.Key.UnicodeChar =3D=3D L'W' - L'A' + 1) { > + break; > + } > + } else if (((KeyData.KeyState.KeyShiftState & > (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) !=3D 0) && > + ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALI= D | > EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) =3D=3D 0)) { > + // > + // For consoles that supports shift state reporting, > + // make sure that only CONTROL shift key is pressed. > + // > + if ((KeyData.Key.UnicodeChar =3D=3D 'w') || (KeyData.Key.UnicodeCh= ar =3D=3D > 'W')) { > + break; > + } > + } > + } >=20 > // update screen with buffer's info > HBufferImageNeedRefresh =3D TRUE; > @@ -1633,6 +1665,19 @@ HMainEditorInit ( > &(HMainEditor.ScreenSize.Row) > ); >=20 > + // > + // Find TextInEx in System Table ConsoleInHandle > + // Per UEFI Spec, TextInEx is required for a console capable platform. > + // > + Status =3D gBS->HandleProtocol ( > + gST->ConsoleInHandle, > + &gEfiSimpleTextInputExProtocolGuid, > + (VOID**)&HMainEditor.TextInputEx > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > // > // Find mouse in System Table ConsoleInHandle > // > @@ -1706,7 +1751,7 @@ HMainEditorInit ( > return EFI_LOAD_ERROR; > } >=20 > - InputBarInit (); > + InputBarInit (HMainEditor.TextInputEx); >=20 > Status =3D HBufferImageInit (); > if (EFI_ERROR (Status)) { > @@ -2058,9 +2103,11 @@ HMainEditorKeyInput ( > VOID > ) > { > - EFI_INPUT_KEY Key; > + EFI_KEY_DATA KeyData; > EFI_STATUS Status; > EFI_SIMPLE_POINTER_STATE MouseState; > + UINTN EventIndex; > + BOOLEAN NoShiftState; > BOOLEAN LengthChange; > UINTN Size; > UINTN OldSize; > @@ -2219,84 +2266,94 @@ HMainEditorKeyInput ( > } > } >=20 > - Status =3D gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); > - if (!EFI_ERROR (Status)) { > - // > - // dispatch to different components' key handling function > - // so not everywhere has to set this variable > - // > - HBufferImageMouseNeedRefresh =3D TRUE; > - > - // > - // clear previous status string > - // > - StatusBarSetRefresh(); > - if (EFI_SUCCESS =3D=3D MenuBarDispatchControlHotKey(&Key)) { > - Status =3D EFI_SUCCESS; > - } else if (Key.ScanCode =3D=3D SCAN_NULL) { > - Status =3D HBufferImageHandleInput (&Key); > - } else if (((Key.ScanCode >=3D SCAN_UP) && (Key.ScanCode <=3D > SCAN_PAGE_DOWN))) { > - Status =3D HBufferImageHandleInput (&Key); > - } else if (((Key.ScanCode >=3D SCAN_F1) && Key.ScanCode <=3D > (SCAN_F12))) { > - Status =3D MenuBarDispatchFunctionKey (&Key); > - } else { > - StatusBarSetStatusString (L"Unknown Command"); > - > - HBufferImageMouseNeedRefresh =3D FALSE; > - } > + Status =3D gBS->WaitForEvent (1, &HMainEditor.TextInputEx- > >WaitForKeyEx, &EventIndex); > + if (!EFI_ERROR (Status) && EventIndex =3D=3D 0) { > + Status =3D HMainEditor.TextInputEx->ReadKeyStrokeEx > (HMainEditor.TextInputEx, &KeyData); > + if (!EFI_ERROR (Status)) { > + // > + // dispatch to different components' key handling function > + // so not everywhere has to set this variable > + // > + HBufferImageMouseNeedRefresh =3D TRUE; >=20 > - if (Status !=3D EFI_SUCCESS && Status !=3D EFI_OUT_OF_RESOURCES) { > // > - // not already has some error status > + // clear previous status string > // > - if (StrCmp (L"", StatusBarGetString()) =3D=3D 0) { > - StatusBarSetStatusString (L"Disk Error. Try Again"); > + StatusBarSetRefresh(); > + // > + // NoShiftState: TRUE when no shift key is pressed. > + // > + NoShiftState =3D ((KeyData.KeyState.KeyShiftState & > EFI_SHIFT_STATE_VALID) =3D=3D 0) || (KeyData.KeyState.KeyShiftState =3D= =3D > EFI_SHIFT_STATE_VALID); > + // > + // dispatch to different components' key handling function > + // > + if (EFI_SUCCESS =3D=3D MenuBarDispatchControlHotKey(&KeyData)) { > + Status =3D EFI_SUCCESS; > + } else if (NoShiftState && KeyData.Key.ScanCode =3D=3D SCAN_NULL= ) { > + Status =3D HBufferImageHandleInput (&KeyData.Key); > + } else if (NoShiftState && ((KeyData.Key.ScanCode >=3D SCAN_UP) = && > (KeyData.Key.ScanCode <=3D SCAN_PAGE_DOWN))) { > + Status =3D HBufferImageHandleInput (&KeyData.Key); > + } else if (NoShiftState && ((KeyData.Key.ScanCode >=3D SCAN_F1) = && > KeyData.Key.ScanCode <=3D SCAN_F12)) { > + Status =3D MenuBarDispatchFunctionKey (&KeyData.Key); > + } else { > + StatusBarSetStatusString (L"Unknown Command"); > + > + HBufferImageMouseNeedRefresh =3D FALSE; > + } > + > + if (Status !=3D EFI_SUCCESS && Status !=3D EFI_OUT_OF_RESOURCES)= { > + // > + // not already has some error status > + // > + if (StrCmp (L"", StatusBarGetString()) =3D=3D 0) { > + StatusBarSetStatusString (L"Disk Error. Try Again"); > + } > } > } > - } > - // > - // decide if has to set length warning > - // > - if (HBufferImage.BufferType !=3D HBufferImageBackupVar.BufferType) { > - LengthChange =3D FALSE; > - } else { > // > - // still the old buffer > + // decide if has to set length warning > // > - if (HBufferImage.BufferType !=3D FileTypeFileBuffer) { > - Size =3D HBufferImageGetTotalSize (); > + if (HBufferImage.BufferType !=3D HBufferImageBackupVar.BufferType)= { > + LengthChange =3D FALSE; > + } else { > + // > + // still the old buffer > + // > + if (HBufferImage.BufferType !=3D FileTypeFileBuffer) { > + Size =3D HBufferImageGetTotalSize (); >=20 > - switch (HBufferImage.BufferType) { > - case FileTypeDiskBuffer: > - OldSize =3D HBufferImage.DiskImage->Size * HBufferImage.DiskIm= age- > >BlockSize; > - break; > + switch (HBufferImage.BufferType) { > + case FileTypeDiskBuffer: > + OldSize =3D HBufferImage.DiskImage->Size * HBufferImage.Disk= Image- > >BlockSize; > + break; >=20 > - case FileTypeMemBuffer: > - OldSize =3D HBufferImage.MemImage->Size; > - break; > + case FileTypeMemBuffer: > + OldSize =3D HBufferImage.MemImage->Size; > + break; >=20 > - default: > - OldSize =3D 0; > - break; > - } > + default: > + OldSize =3D 0; > + break; > + } >=20 > - if (!LengthChange) { > - if (OldSize !=3D Size) { > - StatusBarSetStatusString (L"Disk/Mem Buffer Length should no= t be > changed"); > + if (!LengthChange) { > + if (OldSize !=3D Size) { > + StatusBarSetStatusString (L"Disk/Mem Buffer Length should = not be > changed"); > + } > } > - } >=20 > - if (OldSize !=3D Size) { > - LengthChange =3D TRUE; > - } else { > - LengthChange =3D FALSE; > + if (OldSize !=3D Size) { > + LengthChange =3D TRUE; > + } else { > + LengthChange =3D FALSE; > + } > } > } > + // > + // after handling, refresh editor > + // > + HMainEditorRefresh (); > } > - // > - // after handling, refresh editor > - // > - HMainEditorRefresh (); >=20 > } while (Status !=3D EFI_OUT_OF_RESOURCES && !HEditorExit); >=20 > -- > 2.16.1.windows.1