summaryrefslogtreecommitdiff
path: root/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2018-02-12 21:42:55 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2018-02-13 10:54:45 +0800
commit5563281fa2b31093a1cbd415553b9264c5136e89 (patch)
treea883c85ae8431e7f889717beb34459223ad30292 /ShellPkg/Library/UefiShellDebug1CommandsLib/Edit
parent0a54cd4431c31ab2e72d880a55c31dd08f971cc4 (diff)
downloadedk2-5563281fa2b31093a1cbd415553b9264c5136e89.zip
edk2-5563281fa2b31093a1cbd415553b9264c5136e89.tar.gz
edk2-5563281fa2b31093a1cbd415553b9264c5136e89.tar.bz2
ShellPkg/[hex]edit: use SimpleTextInEx to read console
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>
Diffstat (limited to 'ShellPkg/Library/UefiShellDebug1CommandsLib/Edit')
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c135
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditorTypes.h21
2 files changed, 103 insertions, 53 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c
index 14f51df..a197f80 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c
@@ -1,7 +1,7 @@
/** @file
Implements editor interface functions.
- Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved. <BR>
+ Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
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;
//
// print helpInfo
@@ -1371,14 +1373,39 @@ MainCommandDisplayHelp (
InfoString = 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 != Key.UnicodeChar);
+ while (TRUE) {
+ Status = gBS->WaitForEvent (1, &MainEditor.TextInputEx->WaitForKeyEx, &EventIndex);
+ if (EFI_ERROR (Status) || (EventIndex != 0)) {
+ continue;
+ }
+ Status = MainEditor.TextInputEx->ReadKeyStrokeEx (MainEditor.TextInputEx, &KeyData);
+ if (EFI_ERROR (Status)) {
+ continue;
+ }
+ if ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) {
+ //
+ // For consoles that don't support shift state reporting,
+ // CTRL+W is translated to L'W' - L'A' + 1.
+ //
+ if (KeyData.Key.UnicodeChar == L'W' - L'A' + 1) {
+ break;
+ }
+ } else if (((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) != 0) &&
+ ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID | EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) == 0)) {
+ //
+ // For consoles that supports shift state reporting,
+ // make sure that only CONTROL shift key is pressed.
+ //
+ if ((KeyData.Key.UnicodeChar == 'w') || (KeyData.Key.UnicodeChar == 'W')) {
+ break;
+ }
+ }
+ }
//
// update screen with file buffer's info
//
@@ -1407,6 +1434,7 @@ EFI_EDITOR_GLOBAL_EDITOR MainEditorConst = {
0
},
NULL,
+ NULL,
FALSE,
NULL
};
@@ -1453,6 +1481,19 @@ MainEditorInit (
);
//
+ // Find TextInEx in System Table ConsoleInHandle
+ // Per UEFI Spec, TextInEx is required for a console capable platform.
+ //
+ Status = gBS->HandleProtocol (
+ gST->ConsoleInHandle,
+ &gEfiSimpleTextInputExProtocolGuid,
+ (VOID**)&MainEditor.TextInputEx
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
// Find mouse in System Table ConsoleInHandle
//
Status = gBS->HandleProtocol (
@@ -1521,7 +1562,7 @@ MainEditorInit (
return EFI_LOAD_ERROR;
}
- InputBarInit ();
+ InputBarInit (MainEditor.TextInputEx);
Status = 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;
do {
@@ -1831,46 +1874,52 @@ MainEditorKeyInput (
}
}
- Status = 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 = TRUE;
- //
- // clear previous status string
- //
- StatusBarSetRefresh();
-
- //
- // dispatch to different components' key handling function
- //
- if (EFI_NOT_FOUND != MenuBarDispatchControlHotKey(&Key)) {
- Status = EFI_SUCCESS;
- } else if ((Key.ScanCode == SCAN_NULL) || ((Key.ScanCode >= SCAN_UP) && (Key.ScanCode <= SCAN_PAGE_DOWN))) {
- Status = FileBufferHandleInput (&Key);
- } else if ((Key.ScanCode >= SCAN_F1) && (Key.ScanCode <= SCAN_F12)) {
- Status = MenuBarDispatchFunctionKey (&Key);
- } else {
- StatusBarSetStatusString (L"Unknown Command");
- FileBufferMouseNeedRefresh = FALSE;
- }
-
- if (Status != EFI_SUCCESS && Status != EFI_OUT_OF_RESOURCES) {
+ Status = gBS->WaitForEvent (1, &MainEditor.TextInputEx->WaitForKeyEx, &EventIndex);
+ if (!EFI_ERROR (Status) && EventIndex == 0) {
+ Status = 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 = TRUE;
//
- // not already has some error status
+ // clear previous status string
//
- if (StatusBarGetString() != NULL && StrCmp (L"", StatusBarGetString()) == 0) {
- StatusBarSetStatusString (L"Disk Error. Try Again");
+ StatusBarSetRefresh();
+ //
+ // NoShiftState: TRUE when no shift key is pressed.
+ //
+ NoShiftState = ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) || (KeyData.KeyState.KeyShiftState == EFI_SHIFT_STATE_VALID);
+ //
+ // dispatch to different components' key handling function
+ //
+ if (EFI_NOT_FOUND != MenuBarDispatchControlHotKey(&KeyData)) {
+ Status = EFI_SUCCESS;
+ } else if (NoShiftState && ((KeyData.Key.ScanCode == SCAN_NULL) || ((KeyData.Key.ScanCode >= SCAN_UP) && (KeyData.Key.ScanCode <= SCAN_PAGE_DOWN)))) {
+ Status = FileBufferHandleInput (&KeyData.Key);
+ } else if (NoShiftState && (KeyData.Key.ScanCode >= SCAN_F1) && (KeyData.Key.ScanCode <= SCAN_F12)) {
+ Status = MenuBarDispatchFunctionKey (&KeyData.Key);
+ } else {
+ StatusBarSetStatusString (L"Unknown Command");
+ FileBufferMouseNeedRefresh = FALSE;
+ }
+
+ if (Status != EFI_SUCCESS && Status != EFI_OUT_OF_RESOURCES) {
+ //
+ // not already has some error status
+ //
+ if (StatusBarGetString() != NULL && StrCmp (L"", StatusBarGetString()) == 0) {
+ StatusBarSetStatusString (L"Disk Error. Try Again");
+ }
}
- }
+ }
+ //
+ // after handling, refresh editor
+ //
+ MainEditorRefresh ();
}
- //
- // after handling, refresh editor
- //
- MainEditorRefresh ();
} while (Status != EFI_OUT_OF_RESOURCES && !EditorExit);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditorTypes.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditorTypes.h
index dfd56dd..4cabba7 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditorTypes.h
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditorTypes.h
@@ -1,7 +1,7 @@
/** @file
Declares editor types.
- Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
+ Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
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;
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 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;
} EFI_EDITOR_GLOBAL_EDITOR;