From nobody Sun May 5 02:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1518449617439557.8007197564599; Mon, 12 Feb 2018 07:33:37 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 39BB5223972A8; Mon, 12 Feb 2018 07:27:46 -0800 (PST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 DD8A32215BD94 for ; Mon, 12 Feb 2018 07:27:44 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2018 07:33:34 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.37]) by fmsmga002.fm.intel.com with ESMTP; 12 Feb 2018 07:33:33 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,501,1511856000"; d="scan'208";a="19333525" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Mon, 12 Feb 2018 23:33:30 +0800 Message-Id: <20180212153330.21112-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.16.1.windows.1 Subject: [edk2] [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: , Cc: Jaben Carsey , Felix MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D682 Edit and HexEdit commands assume that SimpleTxtIn translates Ctrl+ 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+ key combinations. The patch changes edit and hexedit to only consumes SimpleTextInEx. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Reported-by: Felix Cc: Felix Cc: Jaben Carsey Reviewed-by: 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(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEdito= r.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 BS= D License which accompanies this distribution. The full text of the license may b= e 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 =20 @@ -1371,14 +1373,39 @@ MainCommandDisplayHelp ( InfoString =3D HiiGetString(gShellDebug1HiiHandle, MainMenuHelpInfo[Cu= rrentLine], NULL); ShellPrintEx (0, CurrentLine+1, L"%E%s%N", InfoString); =20 } - =20 + // // scan for ctrl+w // - do { - gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - } while(SCAN_CONTROL_W !=3D Key.UnicodeChar);=20 + while (TRUE) { + Status =3D gBS->WaitForEvent (1, &MainEditor.TextInputEx->WaitForKeyEx= , &EventIndex); + if (EFI_ERROR (Status) || (EventIndex !=3D 0)) { + continue; + } + Status =3D MainEditor.TextInputEx->ReadKeyStrokeEx (MainEditor.TextInp= utEx, &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_PRESSE= D | EFI_RIGHT_CONTROL_PRESSED)) !=3D 0) && + ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID = | 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.UnicodeChar= =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 SC= AN_UP) && (Key.ScanCode <=3D SCAN_PAGE_DOWN))) { - Status =3D FileBufferHandleInput (&Key); - } else if ((Key.ScanCode >=3D SCAN_F1) && (Key.ScanCode <=3D SCAN_F1= 2)) { - Status =3D MenuBarDispatchFunctionKey (&Key); - } else { - StatusBarSetStatusString (L"Unknown Command"); - FileBufferMouseNeedRefresh =3D FALSE; =20 - } - =20 - if (Status !=3D EFI_SUCCESS && Status !=3D EFI_OUT_OF_RESOURCES) { + Status =3D gBS->WaitForEvent (1, &MainEditor.TextInputEx->WaitForKeyEx= , &EventIndex); + if (!EFI_ERROR (Status) && EventIndex =3D=3D 0) { + Status =3D MainEditor.TextInputEx->ReadKeyStrokeEx (MainEditor.TextI= nputEx, &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"", StatusBarGetStr= ing()) =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_STAT= E_VALID) =3D=3D 0) || (KeyData.KeyState.KeyShiftState =3D=3D EFI_SHIFT_STAT= E_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_NULL= ) || ((KeyData.Key.ScanCode >=3D SCAN_UP) && (KeyData.Key.ScanCode <=3D SCA= N_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; =20 + } + =20 + if (Status !=3D EFI_SUCCESS && Status !=3D EFI_OUT_OF_RESOURCES) { + // + // not already has some error status + // + if (StatusBarGetString() !=3D NULL && StrCmp (L"", StatusBarGetS= tring()) =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/TextEditorTyp= es.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 BS= D License which accompanies this distribution. The full text of the license may b= e 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 number - 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 n= umber + 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/S= hellPkg/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 BS= D License which accompanies this distribution. The full text of the license may b= e 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 Table. **/ 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 CHA= R_CARRIAGE_RETURN) { + if (KeyData.Key.UnicodeChar =3D=3D CHAR_LINEFEED || KeyData.Key.Unicod= eChar =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.UnicodeChar= >=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/S= hellPkg/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 BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -17,10 +17,12 @@ =20 /** Initialize the input bar. + + @param[in] TextInEx Pointer to SimpleTextInEx instance in System Table. **/ VOID InputBarInit ( - VOID + IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx ); =20 /** diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c b/Sh= ellPkg/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 BS= D License which accompanies this distribution. The full text of the license may b= e 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 key=20 (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 ) { - =20 - 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_PRESSE= D | 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.UnicodeChar = <=3D L'Z')) { + ControlIndex =3D KeyData->Key.UnicodeChar - L'A' + 1; + } else if ((KeyData->Key.UnicodeChar >=3D L'a') && (KeyData->Key.Unico= deChar <=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/Sh= ellPkg/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 BS= D License which accompanies this distribution. The full text of the license may b= e 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 key=20 (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/HexEditorT= ypes.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 BS= D License which accompanies this distribution. The full text of the license may b= e 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 colu= mn 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 an= d column number + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInputEx; + BOOLEAN MouseSupported; + EFI_SIMPLE_POINTER_PROTOCOL *MouseInterface; + INT32 MouseAccumulatorX; + INT32 MouseAccumulatorY; + + UINTN SelectStart; // starting from= 1 + UINTN SelectEnd; // starting from= 1 } HEFI_EDITOR_GLOBAL_EDITOR; =20 #endif diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEdi= tor.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 BS= D License which accompanies this distribution. The full text of the license may b= e 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; + =20 + // // print helpInfo =20 + // for (CurrentLine =3D 0; 0 !=3D HexMainMenuHelpInfo[CurrentLine]; Current= Line++) { InfoString =3D HiiGetString(gShellDebug1HiiHandle, HexMainMenuHelpInfo= [CurrentLine] , NULL); ShellPrintEx (0,CurrentLine+1,L"%E%s%N",InfoString); =20 } - =20 + + // // scan for ctrl+w - do { - gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - } while(SCAN_CONTROL_W !=3D Key.UnicodeChar);=20 + // + while (TRUE) { + Status =3D gBS->WaitForEvent (1, &HMainEditor.TextInputEx->WaitForKeyE= x, &EventIndex); + if (EFI_ERROR (Status) || (EventIndex !=3D 0)) { + continue; + } + Status =3D HMainEditor.TextInputEx->ReadKeyStrokeEx (HMainEditor.TextI= nputEx, &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_PRESSE= D | EFI_RIGHT_CONTROL_PRESSED)) !=3D 0) && + ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID = | 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.UnicodeChar= =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_P= AGE_DOWN))) { - Status =3D HBufferImageHandleInput (&Key); - } else if (((Key.ScanCode >=3D SCAN_F1) && Key.ScanCode <=3D (SCAN_F= 12))) { - Status =3D MenuBarDispatchFunctionKey (&Key); - } else { - StatusBarSetStatusString (L"Unknown Command"); - - HBufferImageMouseNeedRefresh =3D FALSE; - } + Status =3D gBS->WaitForEvent (1, &HMainEditor.TextInputEx->WaitForKeyE= x, &EventIndex); + if (!EFI_ERROR (Status) && EventIndex =3D=3D 0) { + Status =3D HMainEditor.TextInputEx->ReadKeyStrokeEx (HMainEditor.Tex= tInputEx, &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_STAT= E_VALID) =3D=3D 0) || (KeyData.KeyState.KeyShiftState =3D=3D EFI_SHIFT_STAT= E_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.DiskImag= e->BlockSize; - break; + switch (HBufferImage.BufferType) { + case FileTypeDiskBuffer: + OldSize =3D HBufferImage.DiskImage->Size * HBufferImage.DiskIm= age->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 not = be changed"); + if (!LengthChange) { + if (OldSize !=3D Size) { + StatusBarSetStatusString (L"Disk/Mem Buffer Length should no= t 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 --=20 2.16.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel