X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellDebug1CommandsLib%2FEdit%2FMainTextEditor.c;h=98e1331ac453267334d1766b9c621d43952192b6;hp=1a8f39a229fc60f5e8dc0283208fe601ccaf9ba8;hb=58793b8838f500955c8a7a548b4b450e81798f6e;hpb=2b578de0b213ecc98d5889ec496d12a56eb3b187 diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c index 1a8f39a229..98e1331ac4 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 - 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 @@ -15,6 +15,32 @@ #include "TextEditor.h" #include "EditStatusBar.h" #include "EditInputBar.h" +#include "EditMenuBar.h" + +// +// the first time editor launch +// +BOOLEAN EditorFirst; + +// +// it's time editor should exit +// +BOOLEAN EditorExit; + +BOOLEAN EditorMouseAction; + +extern EFI_EDITOR_FILE_BUFFER FileBuffer; + +extern BOOLEAN FileBufferNeedRefresh; + +extern BOOLEAN FileBufferOnlyLineNeedRefresh; + +extern BOOLEAN FileBufferMouseNeedRefresh; + +extern EFI_EDITOR_FILE_BUFFER FileBufferBackupVar; + +EFI_EDITOR_GLOBAL_EDITOR MainEditor; + /** Load a file from disk to editor @@ -61,6 +87,16 @@ MainCommandSaveFile ( VOID ); +/** + Show help information for the editor. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +MainCommandDisplayHelp ( + VOID + ); + /** exit editor @@ -121,6 +157,66 @@ MainCommandPasteLine ( VOID ); +/** + Help info that will be displayed. +**/ +EFI_STRING_ID MainMenuHelpInfo[] = { + STRING_TOKEN(STR_EDIT_HELP_TITLE), + STRING_TOKEN(STR_EDIT_HELP_BLANK), + STRING_TOKEN(STR_EDIT_HELP_LIST_TITLE), + STRING_TOKEN(STR_EDIT_HELP_DIV), + STRING_TOKEN(STR_EDIT_HELP_GO_TO_LINE), + STRING_TOKEN(STR_EDIT_HELP_SAVE_FILE), + STRING_TOKEN(STR_EDIT_HELP_EXIT), + STRING_TOKEN(STR_EDIT_HELP_SEARCH), + STRING_TOKEN(STR_EDIT_HELP_SEARCH_REPLACE), + STRING_TOKEN(STR_EDIT_HELP_CUT_LINE), + STRING_TOKEN(STR_EDIT_HELP_PASTE_LINE), + STRING_TOKEN(STR_EDIT_HELP_OPEN_FILE), + STRING_TOKEN(STR_EDIT_HELP_FILE_TYPE), + STRING_TOKEN(STR_EDIT_HELP_BLANK), + STRING_TOKEN(STR_EDIT_HELP_EXIT_HELP), + STRING_TOKEN(STR_EDIT_HELP_BLANK), + STRING_TOKEN(STR_EDIT_HELP_BLANK), + STRING_TOKEN(STR_EDIT_HELP_BLANK), + STRING_TOKEN(STR_EDIT_HELP_BLANK), + STRING_TOKEN(STR_EDIT_HELP_BLANK), + STRING_TOKEN(STR_EDIT_HELP_BLANK), + STRING_TOKEN(STR_EDIT_HELP_BLANK), + STRING_TOKEN(STR_EDIT_HELP_DIV), +0 +}; + +MENU_ITEM_FUNCTION MainControlBasedMenuFunctions[] = { + NULL, + NULL, /* Ctrl - A */ + NULL, /* Ctrl - B */ + NULL, /* Ctrl - C */ + NULL, /* Ctrl - D */ + MainCommandDisplayHelp, /* Ctrl - E */ + MainCommandSearch, /* Ctrl - F */ + MainCommandGotoLine, /* Ctrl - G */ + NULL, /* Ctrl - H */ + NULL, /* Ctrl - I */ + NULL, /* Ctrl - J */ + MainCommandCutLine, /* Ctrl - K */ + NULL, /* Ctrl - L */ + NULL, /* Ctrl - M */ + NULL, /* Ctrl - N */ + MainCommandOpenFile, /* Ctrl - O */ + NULL, /* Ctrl - P */ + MainCommandExit, /* Ctrl - Q */ + MainCommandSearchReplace, /* Ctrl - R */ + MainCommandSaveFile, /* Ctrl - S */ + MainCommandSwitchFileType, /* Ctrl - T */ + MainCommandPasteLine, /* Ctrl - U */ + NULL, /* Ctrl - V */ + NULL, /* Ctrl - W */ + NULL, /* Ctrl - X */ + NULL, /* Ctrl - Y */ + NULL, /* Ctrl - Z */ +}; + EDITOR_MENU_ITEM MainMenuItems[] = { { STRING_TOKEN(STR_EDIT_LIBMENUBAR_GO_TO_LINE), @@ -169,6 +265,11 @@ EDITOR_MENU_ITEM MainMenuItems[] = { STRING_TOKEN(STR_EDIT_LIBMENUBAR_F9), MainCommandSwitchFileType }, + { + STRING_TOKEN(STR_EDIT_LIBMENUBAR_FILE_TYPE), + STRING_TOKEN(STR_EDIT_LIBMENUBAR_F11), + MainCommandSwitchFileType + }, { 0, @@ -388,6 +489,7 @@ MainCommandCutLine ( // IF cursor is not on valid line, an Status String will be prompted : // "Nothing to Cut". // + Line = NULL; Status = FileBufferCutLine (&Line); if (Status == EFI_NOT_FOUND) { return EFI_SUCCESS; @@ -1248,28 +1350,78 @@ MainCommandSaveFile ( return Status; } -EFI_EDITOR_COLOR_ATTRIBUTES OriginalColors; -INTN OriginalMode; - -// -// the first time editor launch -// -BOOLEAN EditorFirst; +/** + Show help information for the editor. -// -// it's time editor should exit -// -BOOLEAN EditorExit; + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +MainCommandDisplayHelp ( + VOID + ) +{ + INT32 CurrentLine; + CHAR16 *InfoString; + EFI_KEY_DATA KeyData; + EFI_STATUS Status; + UINTN EventIndex; + + // + // print helpInfo + // + for (CurrentLine = 0; 0 != MainMenuHelpInfo[CurrentLine]; CurrentLine++) { + InfoString = HiiGetString(gShellDebug1HiiHandle, MainMenuHelpInfo[CurrentLine], NULL); + ShellPrintEx (0, CurrentLine+1, L"%E%s%N", InfoString); + } -BOOLEAN EditorMouseAction; + // + // scan for ctrl+w + // + 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; + } -extern EFI_EDITOR_FILE_BUFFER FileBuffer; + if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) || + (KeyData.KeyState.KeyShiftState == EFI_SHIFT_STATE_VALID)) { + // + // For consoles that don't support/report shift state, + // 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_SHIFT_STATE_VALID) != 0) && + ((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/reports shift state, + // 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 + // + FileBufferRestorePosition (); + FileBufferNeedRefresh = TRUE; + FileBufferOnlyLineNeedRefresh = FALSE; + FileBufferRefresh (); -extern BOOLEAN FileBufferMouseNeedRefresh; + return EFI_SUCCESS; +} -extern EFI_EDITOR_FILE_BUFFER FileBufferBackupVar; +EFI_EDITOR_COLOR_ATTRIBUTES OriginalColors; +INTN OriginalMode; -EFI_EDITOR_GLOBAL_EDITOR MainEditor; // // basic initialization for MainEditor @@ -1277,14 +1429,14 @@ EFI_EDITOR_GLOBAL_EDITOR MainEditor; EFI_EDITOR_GLOBAL_EDITOR MainEditorConst = { &FileBuffer, { - 0, - 0 + {0, 0} }, { 0, 0 }, NULL, + NULL, FALSE, NULL }; @@ -1296,7 +1448,6 @@ EFI_EDITOR_GLOBAL_EDITOR MainEditorConst = { @retval EFI_LOAD_ERROR A load error occured. **/ EFI_STATUS -EFIAPI MainEditorInit ( VOID ) @@ -1331,11 +1482,24 @@ MainEditorInit ( &(MainEditor.ScreenSize.Row) ); + // + // 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 ( - gST->ConIn, + gST->ConsoleInHandle, &gEfiSimplePointerProtocolGuid, (VOID**)&MainEditor.MouseInterface ); @@ -1381,12 +1545,13 @@ MainEditorInit ( // // below will call the five components' init function // - Status = MainTitleBarInit (L"UEFI EDIT 2.0"); + Status = MainTitleBarInit (L"UEFI EDIT"); if (EFI_ERROR (Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_LIBEDITOR_TITLEBAR), gShellDebug1HiiHandle); return EFI_LOAD_ERROR; } + Status = ControlHotKeyInit (MainControlBasedMenuFunctions); Status = MenuBarInit (MainMenuItems); if (EFI_ERROR (Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_LIBEDITOR_MAINMENU), gShellDebug1HiiHandle); @@ -1399,7 +1564,7 @@ MainEditorInit ( return EFI_LOAD_ERROR; } - InputBarInit (); + InputBarInit (MainEditor.TextInputEx); Status = FileBufferInit (); if (EFI_ERROR (Status)) { @@ -1429,7 +1594,6 @@ MainEditorInit ( @retval EFI_LOAD_ERROR A load error occured. **/ EFI_STATUS -EFIAPI MainEditorCleanup ( VOID ) @@ -1473,7 +1637,6 @@ MainEditorCleanup ( Refresh the main editor component. **/ VOID -EFIAPI MainEditorRefresh ( VOID ) @@ -1494,8 +1657,8 @@ MainEditorRefresh ( MainTitleBarRefresh (MainEditor.FileBuffer->FileName, MainEditor.FileBuffer->FileType, MainEditor.FileBuffer->ReadOnly, MainEditor.FileBuffer->FileModified, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row, 0, 0); FileBufferRestorePosition (); - FileBufferRefresh (); } + if (EditorFirst || FileBufferBackupVar.FilePosition.Row != FileBuffer.FilePosition.Row || FileBufferBackupVar.FilePosition.Column != FileBuffer.FilePosition.Column @@ -1504,14 +1667,14 @@ MainEditorRefresh ( StatusBarRefresh (EditorFirst, MainEditor.ScreenSize.Row, MainEditor.ScreenSize.Column, MainEditor.FileBuffer->FilePosition.Row, MainEditor.FileBuffer->FilePosition.Column, MainEditor.FileBuffer->ModeInsert); FileBufferRestorePosition (); - FileBufferRefresh (); } if (EditorFirst) { - MenuBarRefresh (MainEditor.ScreenSize.Row, MainEditor.ScreenSize.Column); FileBufferRestorePosition (); } + FileBufferRefresh (); + // // EditorFirst is now set to FALSE // @@ -1526,7 +1689,6 @@ MainEditorRefresh ( @return The X location of the mouse. **/ INT32 -EFIAPI GetTextX ( IN INT32 GuidX ) @@ -1548,7 +1710,6 @@ GetTextX ( @return The Y location of the mouse. **/ INT32 -EFIAPI GetTextY ( IN INT32 GuidY ) @@ -1572,7 +1733,6 @@ GetTextY ( @retval EFI_NOT_FOUND There was no mouse support found. **/ EFI_STATUS -EFIAPI MainEditorHandleMouseInput ( IN EFI_SIMPLE_POINTER_STATE MouseState ) @@ -1673,14 +1833,14 @@ MainEditorHandleMouseInput ( @retval EFI_OUT_OF_RESOURCES A memory allocation failed. **/ EFI_STATUS -EFIAPI MainEditorKeyInput ( VOID ) { - EFI_INPUT_KEY Key; + EFI_KEY_DATA KeyData; EFI_STATUS Status; EFI_SIMPLE_POINTER_STATE MouseState; + BOOLEAN NoShiftState; do { @@ -1715,39 +1875,50 @@ MainEditorKeyInput ( } } - Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); + // + // CheckEvent() returns Success when non-partial key is pressed. + // + Status = gBS->CheckEvent (MainEditor.TextInputEx->WaitForKeyEx); 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 ((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 = 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 // - // not already has some error status + FileBufferMouseNeedRefresh = TRUE; // - if (StatusBarGetString() != NULL && StrCmp (L"", StatusBarGetString()) == 0) { - StatusBarSetStatusString (L"Disk Error. Try Again"); + // clear previous status string + // + 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 @@ -1768,7 +1939,6 @@ MainEditorKeyInput ( @retval EFI_OUT_OF_RESOURCES A memory allocation failed. **/ EFI_STATUS -EFIAPI MainEditorSetCutLine ( EFI_EDITOR_LINE *Line ) @@ -1800,7 +1970,6 @@ MainEditorSetCutLine ( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI MainEditorBackup ( VOID )