From: jcarsey Date: Fri, 25 Mar 2011 21:15:26 +0000 (+0000) Subject: add Edit and Hexedit shared features. X-Git-Tag: edk2-stable201903~15042 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=2442e62af75a0c5087fce3fb2040e26a485b0d31 add Edit and Hexedit shared features. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11437 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c new file mode 100644 index 0000000000..2c74e06741 --- /dev/null +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c @@ -0,0 +1,330 @@ +/** @file + Implements inputbar interface functions. + + Copyright (c) 2005 - 2011, 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 + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "EditInputBar.h" +#include "UefiShellDebug1CommandsLib.h" + +CHAR16 *mPrompt; // Input bar mPrompt string. +CHAR16 *mReturnString; // The returned string. +UINTN StringSize; // Size of mReturnString space size. + +/** + Initialize the input bar. +**/ +VOID +EFIAPI +InputBarInit ( + VOID + ) +{ + mPrompt = NULL; + mReturnString = NULL; + StringSize = 0; +} + +/** + Cleanup function for input bar. +**/ +VOID +EFIAPI +InputBarCleanup ( + VOID + ) +{ + // + // free input bar's prompt and input string + // + SHELL_FREE_NON_NULL (mPrompt); + SHELL_FREE_NON_NULL (mReturnString); + mPrompt = NULL; + mReturnString = NULL; +} + +/** + Display the prompt. + Do the requesting of input. + + @param[in] LastColumn The last printable column. + @param[in] LastRow The last printable row. +**/ +VOID +EFIAPI +InputBarPrintInput ( + IN UINTN LastColumn, + IN UINTN LastRow + ) +{ + UINTN Limit; + UINTN Size; + CHAR16 *Buffer; + UINTN Index; + UINTN mPromptLen; + + mPromptLen = StrLen (mPrompt); + Limit = LastColumn - mPromptLen - 1; + Size = StrLen (mReturnString); + + // + // check whether the mPrompt length and input length will + // exceed limit + // + if (Size <= Limit) { + Buffer = mReturnString; + } else { + Buffer = mReturnString + Size - Limit; + } + + gST->ConOut->EnableCursor (gST->ConOut, FALSE); + + ShellPrintEx (((INT32)mPromptLen), ((INT32)LastRow) - 4, L"%s", Buffer); + Size = StrLen (Buffer); + + // + // print " " after mPrompt + // + for (Index = Size; Index < Limit; Index++) { + ShellPrintEx ((INT32)(mPromptLen + Size), ((INT32)LastRow) - 4, L" "); + } + + gST->ConOut->EnableCursor (gST->ConOut, TRUE); + gST->ConOut->SetCursorPosition (gST->ConOut, Size + mPromptLen, LastRow - 4); +} + +typedef struct { + UINT32 Foreground : 4; + UINT32 Background : 4; +} INPUT_BAR_COLOR_ATTRIBUTES; + +typedef union { + INPUT_BAR_COLOR_ATTRIBUTES Colors; + UINTN Data; +} INPUT_BAR_COLOR_UNION; + + +/** + The refresh function for InputBar, it will wait for user input + + @param[in] LastRow The last printable row. + @param[in] LastColumn The last printable column. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +InputBarRefresh ( + UINTN LastRow, + UINTN LastColumn + ) +{ + INPUT_BAR_COLOR_UNION Orig; + INPUT_BAR_COLOR_UNION New; + EFI_INPUT_KEY Key; + UINTN Size; + EFI_STATUS Status; + BOOLEAN NoDisplay; + UINTN Limit; + UINTN mPromptLen; + UINTN EventIndex; + UINTN CursorRow; + UINTN CursorCol; + + // + // variable initialization + // + Size = 0; + Status = EFI_SUCCESS; + + // + // back up the old screen attributes + // + CursorCol = gST->ConOut->Mode->CursorColumn; + CursorRow = gST->ConOut->Mode->CursorRow; + Orig.Data = gST->ConOut->Mode->Attribute; + New.Colors.Foreground = Orig.Colors.Background; + New.Colors.Background = Orig.Colors.Foreground; + + gST->ConOut->SetAttribute (gST->ConOut, New.Data); + + // + // clear input bar + // + EditorClearLine (LastRow - 3, LastColumn, LastRow); + + gST->ConOut->SetCursorPosition (gST->ConOut, 0, LastRow - 4); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_LIBINPUTBAR_MAININPUTBAR), gShellDebug1HiiHandle, mPrompt); + + // + // that's the maximum input length that can be displayed on screen + // + mPromptLen = StrLen (mPrompt); + Limit = LastColumn - mPromptLen; + + // + // this is a selection mPrompt, cursor will stay in edit area + // actually this is for search , search/replace + // + if (StrStr (mPrompt, L"Yes/No")) { + NoDisplay = TRUE; + gST->ConOut->SetCursorPosition (gST->ConOut, CursorCol, CursorRow); + gST->ConOut->SetAttribute (gST->ConOut, Orig.Data); + } else { + NoDisplay = FALSE; + } + // + // wait for user input + // + for (;;) { + gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); + Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); + if (EFI_ERROR (Status)) { + continue; + } + // + // pressed ESC + // + if (Key.ScanCode == SCAN_ESC) { + Size = 0; + Status = EFI_NOT_READY; + break; + } + // + // return pressed + // + if (Key.UnicodeChar == CHAR_LINEFEED || Key.UnicodeChar == CHAR_CARRIAGE_RETURN) { + break; + } else if (Key.UnicodeChar == CHAR_BACKSPACE) { + // + // backspace + // + if (Size > 0) { + Size--; + mReturnString[Size] = CHAR_NULL; + if (!NoDisplay) { + + InputBarPrintInput (LastColumn, LastRow); + + } + } + } else if (Key.UnicodeChar <= 127 && Key.UnicodeChar >= 32) { + // + // VALID ASCII char pressed + // + mReturnString[Size] = Key.UnicodeChar; + + // + // should be less than specified length + // + if (Size >= StringSize) { + continue; + } + + Size++; + + mReturnString[Size] = CHAR_NULL; + + if (!NoDisplay) { + + InputBarPrintInput (LastColumn, LastRow); + + } else { + // + // if just choose yes/no + // + break; + } + + } + } + + mReturnString[Size] = CHAR_NULL; + + + // + // restore screen attributes + // + gST->ConOut->SetCursorPosition (gST->ConOut, CursorCol, CursorRow); + gST->ConOut->SetAttribute (gST->ConOut, Orig.Data); + + return Status; +} + +/** + SetPrompt and wait for input. + + @param[in] Str The prompt string. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +InputBarSetPrompt ( + IN CONST CHAR16 *Str + ) +{ + // + // FREE the old mPrompt string + // + SHELL_FREE_NON_NULL (mPrompt); + + mPrompt = CatSPrint (NULL, L"%s ", Str); + if (mPrompt == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + return EFI_SUCCESS; +} + +/** + Set the size of the string in characters. + + @param[in] Size The max number of characters to accept. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +InputBarSetStringSize ( + UINTN Size + ) +{ + // + // free the old ReturnStirng + // + SHELL_FREE_NON_NULL (mReturnString); + + StringSize = Size; + mReturnString = AllocateZeroPool ((StringSize + 1) * sizeof(mReturnString[0])); + if (mReturnString == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + return EFI_SUCCESS; +} + +/** + Function to retrieve the input from the user. + + @retval NULL No input has been received. + @return The string that was input. +**/ +CONST CHAR16* +EFIAPI +InputBarGetString ( + VOID + ) +{ + return (mReturnString); +} diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.h new file mode 100644 index 0000000000..c8557a83f1 --- /dev/null +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.h @@ -0,0 +1,91 @@ +/** @file + Declares imputbar interface functions. + + Copyright (c) 2005 - 2011, 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 + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef _LIB_INPUT_BAR_H_ +#define _LIB_INPUT_BAR_H_ + +/** + Initialize the input bar. +**/ +VOID +EFIAPI +InputBarInit ( + VOID + ); + +/** + Cleanup function for input bar. +**/ +VOID +EFIAPI +InputBarCleanup ( + VOID + ); + +/** + The refresh function for InputBar, it will wait for user input + + @param[in] LastRow The last printable row. + @param[in] LastColumn The last printable column. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +InputBarRefresh ( + UINTN LastRow, + UINTN LastColumn + ); + +/** + SetPrompt and wait for input. + + @param[in] Str The prompt string. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +InputBarSetPrompt ( + IN CONST CHAR16 *Str + ); + +/** + Set the size of the string in characters. + + @param[in] Size The max number of characters to accept. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +InputBarSetStringSize ( + UINTN Size + ); + +/** + Function to retrieve the input from the user. + + @retval NULL No input has been received. + @return The string that was input. +**/ +CONST CHAR16* +EFIAPI +InputBarGetString ( + VOID + ); + +#endif diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c new file mode 100644 index 0000000000..390c707bc6 --- /dev/null +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c @@ -0,0 +1,152 @@ +/** @file + implements menubar interface functions. + + Copyright (c) 2005 - 2011, 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 + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "EditMenuBar.h" +#include "UefiShellDebug1CommandsLib.h" +#include "EditStatusBar.h" + +EDITOR_MENU_ITEM *MenuItems; +UINTN NumItems; + +/** + Cleanup function for a menu bar. frees all allocated memory. +**/ +VOID +EFIAPI +MenuBarCleanup ( + VOID + ) +{ + SHELL_FREE_NON_NULL(MenuItems); +} + +/** + Initializa the menu bar with the specified items. + + @param[in] Items The items to display and their functions. + + @retval EFI_SUCCESS The initialization was correct. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +MenuBarInit ( + IN CONST EDITOR_MENU_ITEM *Items + ) +{ + CONST EDITOR_MENU_ITEM *ItemsWalker; + + for (NumItems = 0, ItemsWalker = Items ; ItemsWalker != NULL && ItemsWalker->Function != NULL ; ItemsWalker++,NumItems++); + + MenuItems = AllocateZeroPool((NumItems+1) * sizeof(EDITOR_MENU_ITEM)); + if (MenuItems == NULL) { + return EFI_OUT_OF_RESOURCES; + } + CopyMem(MenuItems, Items, (NumItems+1) * sizeof(EDITOR_MENU_ITEM)); + return EFI_SUCCESS; +} + +/** + Refresh function for the menu bar. + + @param[in] LastRow The last printable row. + @param[in] LastCol The last printable column. + + @retval EFI_SUCCESS The refresh was successful. +**/ +EFI_STATUS +EFIAPI +MenuBarRefresh ( + IN CONST UINTN LastRow, + IN CONST UINTN LastCol + ) +{ + EDITOR_MENU_ITEM *Item; + UINTN Col; + UINTN Row; + UINTN Width; + CHAR16 *NameString; + CHAR16 *FunctionKeyString; + + // + // variable initialization + // + Col = 1; + Row = (LastRow - 2); + + // + // clear menu bar rows + // + EditorClearLine (LastRow - 2, LastCol, LastRow); + EditorClearLine (LastRow - 1, LastCol, LastRow); + EditorClearLine (LastRow , LastCol, LastRow); + + + // + // print out the menu items + // + for (Item = MenuItems; Item != NULL && Item->Function != NULL; Item++) { + + + NameString = HiiGetString(gShellDebug1HiiHandle, Item->NameToken, NULL); + + + Width = MAX ((StrLen (NameString) + 6), 20); + if (((Col + Width) > LastCol)) { + Row++; + Col = 1; + } + + FunctionKeyString = HiiGetString(gShellDebug1HiiHandle, Item->FunctionKeyToken, NULL); + + ShellPrintEx ((INT32)(Col) - 1, (INT32)(Row) - 1, L"%E%s%N %H%s%N ", FunctionKeyString, NameString); + + FreePool (NameString); + FreePool (FunctionKeyString); + Col += Width; + } + + return EFI_SUCCESS; +} + +/** + Function to dispatch the correct function based on a function key (F1...) + + @param[in] Key The pressed key. + + @retval EFI_NOT_FOUND The key was not a valid function key + (an error was sent to the status bar). + @return The return value from the called dispatch function. +**/ +EFI_STATUS +EFIAPI +MenuBarDispatchFunctionKey ( + IN CONST EFI_INPUT_KEY *Key + ) +{ + UINTN Index; + + Index = Key->ScanCode - SCAN_F1; + + // + // check whether in range + // + if (Index > (NumItems - 1)) { + StatusBarSetStatusString (L"Unknown Command"); + return EFI_SUCCESS; + } + + return (MenuItems[Index].Function ()); +} + diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.h new file mode 100644 index 0000000000..407f259fca --- /dev/null +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.h @@ -0,0 +1,83 @@ +/** @file + Declares menubar interface functions. + + Copyright (c) 2005 - 2011, 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 + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef _LIB_MENU_BAR_H_ +#define _LIB_MENU_BAR_H_ + +typedef +EFI_STATUS +(EFIAPI *MENU_ITEM_FUNCTION) ( + VOID + ); + +typedef struct _EDITOR_MENU_ITEM { + EFI_STRING_ID NameToken; + CHAR16 FunctionKeyToken; + MENU_ITEM_FUNCTION Function; +} EDITOR_MENU_ITEM; + +/** + Initializa the menu bar with the specified items. + + @param[in] Items The items to display and their functions. + + @retval EFI_SUCCESS The initialization was correct. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +MenuBarInit ( + IN CONST EDITOR_MENU_ITEM *Items + ); + +/** + Cleanup function for a menu bar. frees all allocated memory. +**/ +VOID +EFIAPI +MenuBarCleanup ( + VOID + ); + +/** + Refresh function for the menu bar. + + @param[in] LastRow The last printable row. + @param[in] LastCol The last printable column. + + @retval EFI_SUCCESS The refresh was successful. +**/ +EFI_STATUS +EFIAPI +MenuBarRefresh ( + IN CONST UINTN LastRow, + IN CONST UINTN LastCol + ); + +/** + Function to dispatch the correct function based on a function key (F1...) + + @param[in] Key The pressed key. + + @retval EFI_NOT_FOUND The key was not a valid function key + (an error was sent to the status bar). + @return The return value from the called dispatch function. +**/ +EFI_STATUS +EFIAPI +MenuBarDispatchFunctionKey ( + IN CONST EFI_INPUT_KEY *Key + ); + +#endif diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c new file mode 100644 index 0000000000..3fd604d818 --- /dev/null +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c @@ -0,0 +1,227 @@ +/** @file + Implements statusbar interface functions. + + Copyright (c) 2005 - 2011, 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 + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "EditStatusBar.h" +#include "UefiShellDebug1CommandsLib.h" + +CHAR16 *StatusString; +BOOLEAN StatusBarNeedRefresh; +BOOLEAN StatusStringChanged; + +/** + Initialization function for Status Bar. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. + @sa StatusBarSetStatusString +**/ +EFI_STATUS +EFIAPI +StatusBarInit ( + VOID + ) +{ + // + // initialize the statusbar + // + StatusString = NULL; + StatusBarNeedRefresh = TRUE; + StatusStringChanged = FALSE; + + // + // status string set to "" + // + return (StatusBarSetStatusString (L"")); +} + +/** + Cleanup function for the status bar. +**/ +VOID +EFIAPI +StatusBarCleanup ( + VOID + ) +{ + // + // free the status string and backvar's status string + // + SHELL_FREE_NON_NULL (StatusString); +} + +typedef struct { + UINT32 Foreground : 4; + UINT32 Background : 4; +} STATUS_BAR_COLOR_ATTRIBUTES; + +typedef union { + STATUS_BAR_COLOR_ATTRIBUTES Colors; + UINTN Data; +} STATUS_BAR_COLOR_UNION; + +/** + Cause the status bar to refresh it's printing on the screen. + + @param[in] EditorFirst TRUE to indicate the first launch of the editor. + FALSE otherwise. + @param[in] LastRow LastPrintable row. + @param[in] LastCol Last printable column. + @param[in] FileRow Row in the file. + @param[in] FileCol Column in the file. + @param[in] InsertMode TRUE to indicate InsertMode. FALSE otherwise. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +StatusBarRefresh ( + IN BOOLEAN EditorFirst, + IN UINTN LastRow, + IN UINTN LastCol, + IN UINTN FileRow, + IN UINTN FileCol, + IN BOOLEAN InsertMode + ) +{ + STATUS_BAR_COLOR_UNION Orig; + STATUS_BAR_COLOR_UNION New; + + if (!StatusStringChanged && StatusBarNeedRefresh) { + StatusBarSetStatusString (L"\0"); + } + // + // when it's called first time after editor launch, so refresh is mandatory + // + if (!StatusBarNeedRefresh && !StatusStringChanged) { + return EFI_SUCCESS; + } + + // + // back up the screen attributes + // + Orig.Data = gST->ConOut->Mode->Attribute; + New.Colors.Foreground = Orig.Colors.Background; + New.Colors.Background = Orig.Colors.Foreground; + + gST->ConOut->EnableCursor (gST->ConOut, FALSE); + gST->ConOut->SetAttribute (gST->ConOut, New.Data); + + // + // clear status bar + // + EditorClearLine (LastRow - 3, LastCol, LastRow); + + // + // print row, column fields + // + ShellPrintEx ( + 0, + (INT32)(LastRow) - 4, + L" Row: %d Col: %d %s", + FileRow, + FileCol, + StatusString + ); + + // + // print insert mode field + // + if (InsertMode) { + ShellPrintEx ((INT32)(LastCol) - 10, (INT32)(LastRow) - 4, L"|%s|", L"INS"); + } else { + ShellPrintEx ((INT32)(LastCol) - 10, (INT32)(LastRow) - 4, L"|%s|", L"OVR"); + } + // + // restore the old screen attributes + // + gST->ConOut->SetAttribute (gST->ConOut, Orig.Data); + + // + // restore position in edit area + // + gST->ConOut->EnableCursor (gST->ConOut, TRUE); + + StatusBarNeedRefresh = FALSE; + StatusStringChanged = FALSE; + + return EFI_SUCCESS; +} + +/** + Set the status string text part. + + @param[in] Str The string to use. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +StatusBarSetStatusString ( + IN CHAR16 *Str + ) +{ + StatusStringChanged = TRUE; + + // + // free the old status string + // + SHELL_FREE_NON_NULL (StatusString); + StatusString = CatSPrint (NULL, L"%s", Str); + if (StatusString == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + return EFI_SUCCESS; +} + +/** + Function to retrieve the current status string. + + @return The string that is used. +**/ +CONST CHAR16* +EFIAPI +StatusBarGetString ( + VOID + ) +{ + return (StatusString); +} + +/** + Function to set the need refresh boolean to TRUE. +**/ +VOID +EFIAPI +StatusBarSetRefresh( + VOID + ) +{ + StatusBarNeedRefresh = TRUE; +} + +/** + Function to get the need refresh boolean to TRUE. + + @retval TRUE The status bar needs to be refreshed. +**/ +BOOLEAN +EFIAPI +StatusBarGetRefresh( + VOID + ) +{ + return (StatusBarNeedRefresh); +} diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.h new file mode 100644 index 0000000000..debf83a9ec --- /dev/null +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.h @@ -0,0 +1,109 @@ +/** @file + Declares statusbar interface functions. + + Copyright (c) 2005 - 2011, 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 + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef _LIB_STATUS_BAR_H_ +#define _LIB_STATUS_BAR_H_ + +/** + Initialization function for Status Bar. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. + @sa StatusBarSetStatusString +**/ +EFI_STATUS +EFIAPI +StatusBarInit ( + VOID + ); + +/** + Cleanup function for the status bar. +**/ +VOID +EFIAPI +StatusBarCleanup ( + VOID + ); + +/** + Cause the status bar to refresh it's printing on the screen. + + @param[in] EditorFirst TRUE to indicate the first launch of the editor. + FALSE otherwise. + @param[in] LastRow LastPrintable row. + @param[in] LastCol Last printable column. + @param[in] FileRow Row in the file. + @param[in] FileCol Column in the file. + @param[in] InsertMode TRUE to indicate InsertMode. FALSE otherwise. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +StatusBarRefresh ( + IN BOOLEAN EditorFirst, + IN UINTN LastRow, + IN UINTN LastCol, + IN UINTN FileRow, + IN UINTN FileCol, + IN BOOLEAN InsertMode + ); + +/** + Set the status string text part. + + @param[in] Str The string to use. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +StatusBarSetStatusString ( + IN CHAR16 *Str + ); + +/** + Function to retrieve the current status string. + + @return The string that is used. +**/ +CONST CHAR16* +EFIAPI +StatusBarGetString ( + VOID + ); + +/** + Function to set the need refresh boolean to TRUE. +**/ +VOID +EFIAPI +StatusBarSetRefresh( + VOID + ); + +/** + Function to get the need refresh boolean to TRUE. + + @retval TRUE The status bar needs to be refreshed. +**/ +BOOLEAN +EFIAPI +StatusBarGetRefresh( + VOID + ); + +#endif diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.c new file mode 100644 index 0000000000..1f71c8b18b --- /dev/null +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.c @@ -0,0 +1,200 @@ +/** @file + Implements titlebar interface functions. + + Copyright (c) 2005 - 2011, 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 + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "EditTitleBar.h" +#include "UefiShellDebug1CommandsLib.h" + +CHAR16 *Title = NULL; + +/** + Initialize a title bar. + + @param[in] Prompt The prompt to print in the title bar. + + @retval EFI_SUCCESS The initialization was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +MainTitleBarInit ( + CONST CHAR16 *Prompt + ) +{ + SHELL_FREE_NON_NULL (Title); + if (Prompt == NULL) { + Title = CatSPrint (NULL, L""); + } else { + // + // set Title + // + Title = CatSPrint (NULL, L"%s", Prompt); + } + if (Title == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + return EFI_SUCCESS; +} + +/** + Clean up the memory used. +**/ +VOID +EFIAPI +MainTitleBarCleanup ( + VOID + ) +{ + SHELL_FREE_NON_NULL (Title); + Title = NULL; +} + +typedef struct { + UINT32 Foreground : 4; + UINT32 Background : 4; +} TITLE_BAR_COLOR_ATTRIBUTES; + +typedef union { + TITLE_BAR_COLOR_ATTRIBUTES Colors; + UINTN Data; +} TITLE_BAR_COLOR_UNION; + +/** + Refresh function for MainTitleBar + + @param[in] FileName The open file's name (or NULL). + @param[in] FileType The type fo the file. + @param[in] ReadOnly TRUE if the file is read only. FALSE otherwise. + @param[in] Modified TRUE if the file was modified. FALSE otherwise. + @param[in] LastCol The last printable column. + @param[in] LastRow The last printable row. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +MainTitleBarRefresh ( + IN CONST CHAR16 *FileName OPTIONAL, + IN CONST EDIT_FILE_TYPE FileType, + IN BOOLEAN ReadOnly, + IN BOOLEAN Modified, + IN UINTN LastCol, + IN UINTN LastRow + ) +{ + TITLE_BAR_COLOR_UNION Orig; + TITLE_BAR_COLOR_UNION New; + CONST CHAR16 *FileNameTmp; + INTN TempInteger; + + + // + // backup the old screen attributes + // + Orig.Data = gST->ConOut->Mode->Attribute; + New.Colors.Foreground = Orig.Colors.Background; + New.Colors.Background = Orig.Colors.Foreground; + + gST->ConOut->SetAttribute (gST->ConOut, New.Data); + + // + // clear the title line + // + EditorClearLine (1, LastCol, LastRow); + + if (Title != NULL) { + // + // print the new title bar prefix + // + ShellPrintEx ( + 0, + 0, + L"%s ", + Title + ); + } + if (FileName == NULL) { + gST->ConOut->SetAttribute (gST->ConOut, Orig.Data); + return EFI_SUCCESS; + } + // + // First Extract the FileName from fullpath + // + FileNameTmp = FileName; + for (TempInteger = StrLen (FileNameTmp) - 1; TempInteger >= 0; TempInteger--) { + if (FileNameTmp[TempInteger] == L'\\') { + break; + } + } + + FileNameTmp = FileNameTmp + TempInteger + 1; + + // + // the space for file name is 20 characters + // + if (StrLen (FileNameTmp) <= 20) { + ShellPrintEx (-1,-1, L"%s ", FileNameTmp); + for (TempInteger = StrLen (FileNameTmp); TempInteger < 20; TempInteger++) { + ShellPrintEx (-1,-1, L" "); + } + + } else { + for (TempInteger = 0; TempInteger < 17; TempInteger++) { + ShellPrintEx (-1,-1, L"%c", FileNameTmp[TempInteger]); + } + // + // print "..." + // + ShellPrintEx (-1,-1, L"... "); + } + // + // print file type field + // + switch (FileType){ + case FileTypeAscii: + case FileTypeUnicode: + if (FileType == FileTypeAscii){ + ShellPrintEx (-1,-1, L" UNICODE "); + } + // + // print read-only field for text files + // + if (ReadOnly) { + ShellPrintEx (-1,-1, L"ReadOnly "); + } else { + ShellPrintEx (-1,-1, L" "); + } + break; + case FileTypeDiskBuffer: + case FileTypeMemBuffer: + // + // Print the offset. + // + ASSERT(FALSE); + case FileTypeFileBuffer: + break; + } + // + // print modified field + // + if (Modified) { + ShellPrintEx (-1,-1, L"Modified"); + } + // + // restore the old attribute + // + gST->ConOut->SetAttribute (gST->ConOut, Orig.Data); + + return EFI_SUCCESS; +} diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.h new file mode 100644 index 0000000000..908b5a3947 --- /dev/null +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.h @@ -0,0 +1,73 @@ +/** @file + Declares titlebar interface functions. + + Copyright (c) 2005 - 2011, 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 + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef _LIB_TITLE_BAR_H_ +#define _LIB_TITLE_BAR_H_ + +/** + Initialize a title bar. + + @param[in] Prompt The prompt to print in the title bar. + + @retval EFI_SUCCESS The initialization was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +MainTitleBarInit ( + CONST CHAR16 *Prompt + ); + +/** + Clean up the memory used. +**/ +VOID +EFIAPI +MainTitleBarCleanup ( + VOID + ); + +typedef enum { + FileTypeNone, + FileTypeAscii, + FileTypeUnicode, + FileTypeDiskBuffer, + FileTypeMemBuffer, + FileTypeFileBuffer +} EDIT_FILE_TYPE; + +/** + Refresh function for MainTitleBar + + @param[in] FileName The open file's name (or NULL). + @param[in] FileType The type fo the file. + @param[in] ReadOnly TRUE if the file is read only. FALSE otherwise. + @param[in] Modified TRUE if the file was modified. FALSE otherwise. + @param[in] LastCol The last printable column. + @param[in] LastRow The last printable row. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +MainTitleBarRefresh ( + IN CONST CHAR16 *FileName OPTIONAL, + IN CONST EDIT_FILE_TYPE FileType, + IN BOOLEAN ReadOnly, + IN BOOLEAN Modified, + IN UINTN LastCol, + IN UINTN LastRow + ); + +#endif