2010-09-14 05:18:09 +00:00
|
|
|
/** @file
|
|
|
|
|
Main file for attrib shell level 2 function.
|
|
|
|
|
|
2016-09-23 09:03:16 -07:00
|
|
|
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
|
2015-02-04 22:25:01 +00:00
|
|
|
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
2018-06-27 21:13:38 +08:00
|
|
|
Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. <BR>
|
2019-04-03 16:07:06 -07:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2010-09-14 05:18:09 +00:00
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
#include "UefiShellLevel3CommandsLib.h"
|
|
|
|
|
|
2016-09-23 09:03:16 -07:00
|
|
|
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
|
|
|
|
{ L"-sfo", TypeFlag },
|
|
|
|
|
{ NULL, TypeMax }
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-06 23:21:44 +02:00
|
|
|
/** Mapping of Background colors.
|
|
|
|
|
**/
|
|
|
|
|
STATIC CONST UINTN mClsBackgroundColorMap[] = {
|
|
|
|
|
EFI_BACKGROUND_BLACK,
|
|
|
|
|
EFI_BACKGROUND_BLUE,
|
|
|
|
|
EFI_BACKGROUND_GREEN,
|
|
|
|
|
EFI_BACKGROUND_CYAN,
|
|
|
|
|
EFI_BACKGROUND_RED,
|
|
|
|
|
EFI_BACKGROUND_MAGENTA,
|
|
|
|
|
EFI_BACKGROUND_BROWN,
|
|
|
|
|
EFI_BACKGROUND_LIGHTGRAY
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** Mapping of Foreground colors.
|
|
|
|
|
**/
|
|
|
|
|
STATIC CONST UINTN mClsForegroundColorMap[] = {
|
|
|
|
|
EFI_BLACK,
|
|
|
|
|
EFI_BLUE,
|
|
|
|
|
EFI_GREEN,
|
|
|
|
|
EFI_CYAN,
|
|
|
|
|
EFI_RED,
|
|
|
|
|
EFI_MAGENTA,
|
|
|
|
|
EFI_BROWN,
|
|
|
|
|
EFI_LIGHTGRAY,
|
|
|
|
|
EFI_DARKGRAY,
|
|
|
|
|
EFI_LIGHTBLUE,
|
|
|
|
|
EFI_LIGHTGREEN,
|
|
|
|
|
EFI_LIGHTCYAN,
|
|
|
|
|
EFI_LIGHTRED,
|
|
|
|
|
EFI_LIGHTMAGENTA,
|
|
|
|
|
EFI_YELLOW,
|
|
|
|
|
EFI_WHITE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Parse a decimal cls color argument.
|
|
|
|
|
|
|
|
|
|
@param[in] ColorStr Command-line argument to parse.
|
|
|
|
|
@param[in] MaxValue Maximum accepted value.
|
|
|
|
|
@param[in] MaxLength Maximum accepted string length.
|
|
|
|
|
@param[out] Color Parsed color index.
|
|
|
|
|
|
|
|
|
|
@retval SHELL_SUCCESS The argument is valid.
|
|
|
|
|
@retval SHELL_INVALID_PARAMETER The argument is invalid.
|
|
|
|
|
**/
|
|
|
|
|
STATIC
|
|
|
|
|
SHELL_STATUS
|
|
|
|
|
GetClsColorIndex (
|
|
|
|
|
IN CONST CHAR16 *ColorStr,
|
|
|
|
|
IN UINTN MaxValue,
|
|
|
|
|
IN UINTN MaxLength,
|
|
|
|
|
OUT UINTN *Color
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
ASSERT (Color != NULL);
|
|
|
|
|
|
|
|
|
|
if ((ShellStrToUintn (ColorStr) > MaxValue) || (StrLen (ColorStr) > MaxLength) || !ShellIsDecimalDigitCharacter (*ColorStr)) {
|
|
|
|
|
return SHELL_INVALID_PARAMETER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*Color = ShellStrToUintn (ColorStr);
|
|
|
|
|
return SHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 14:53:52 +02:00
|
|
|
/** Main function of the 'Cls' command.
|
2010-09-14 05:18:09 +00:00
|
|
|
|
2026-04-28 14:53:52 +02:00
|
|
|
@param[in] Package List of input parameter for the command.
|
2010-09-14 05:18:09 +00:00
|
|
|
**/
|
2026-04-28 14:53:52 +02:00
|
|
|
STATIC
|
2010-09-14 05:18:09 +00:00
|
|
|
SHELL_STATUS
|
2026-04-28 14:53:52 +02:00
|
|
|
MainCmdCls (
|
|
|
|
|
LIST_ENTRY *Package
|
2010-09-14 05:18:09 +00:00
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
UINTN Background;
|
2016-09-23 09:03:16 -07:00
|
|
|
UINTN Foreground;
|
2010-09-14 05:18:09 +00:00
|
|
|
SHELL_STATUS ShellStatus;
|
2016-09-23 09:03:16 -07:00
|
|
|
CONST CHAR16 *BackColorStr;
|
|
|
|
|
CONST CHAR16 *ForeColorStr;
|
2026-04-06 23:21:44 +02:00
|
|
|
UINTN ColorIndex;
|
2010-09-14 05:18:09 +00:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Initialize variables
|
|
|
|
|
//
|
2026-04-28 14:53:52 +02:00
|
|
|
ShellStatus = SHELL_SUCCESS;
|
|
|
|
|
Background = 0;
|
|
|
|
|
Foreground = 0;
|
2026-04-28 14:45:48 +02:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// check for "-?"
|
|
|
|
|
//
|
|
|
|
|
if (ShellCommandLineGetFlag (Package, L"-?")) {
|
|
|
|
|
ASSERT (FALSE);
|
2026-04-28 18:25:08 +02:00
|
|
|
return ShellStatus;
|
2026-04-28 14:45:48 +02:00
|
|
|
} else if (ShellCommandLineGetFlag (Package, L"-sfo")) {
|
|
|
|
|
if (ShellCommandLineGetCount (Package) > 1) {
|
|
|
|
|
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"cls");
|
|
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
|
} else {
|
|
|
|
|
Background = (gST->ConOut->Mode->Attribute >> 4) & 0x7;
|
|
|
|
|
Foreground = gST->ConOut->Mode->Attribute & 0x0F;
|
|
|
|
|
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_SFO_HEADER), gShellLevel3HiiHandle, L"cls");
|
|
|
|
|
ShellPrintHiiDefaultEx (
|
|
|
|
|
STRING_TOKEN (STR_CLS_OUTPUT_SFO),
|
|
|
|
|
gShellLevel3HiiHandle,
|
|
|
|
|
gST->ConOut->Mode->Attribute,
|
|
|
|
|
Foreground,
|
|
|
|
|
Background
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-04-28 18:25:08 +02:00
|
|
|
|
|
|
|
|
return ShellStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// If there are 0 value parameters, clear sceen
|
|
|
|
|
//
|
|
|
|
|
BackColorStr = ShellCommandLineGetRawValue (Package, 1);
|
|
|
|
|
ForeColorStr = ShellCommandLineGetRawValue (Package, 2);
|
|
|
|
|
|
|
|
|
|
if ((BackColorStr == NULL) && (ForeColorStr == NULL)) {
|
2010-09-14 05:18:09 +00:00
|
|
|
//
|
2026-04-28 18:25:08 +02:00
|
|
|
// clear screen
|
2010-09-14 05:18:09 +00:00
|
|
|
//
|
2026-04-28 18:25:08 +02:00
|
|
|
gST->ConOut->ClearScreen (gST->ConOut);
|
|
|
|
|
return ShellStatus;
|
|
|
|
|
} else if (ShellCommandLineGetCount (Package) > 3) {
|
|
|
|
|
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"cls");
|
|
|
|
|
return SHELL_INVALID_PARAMETER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (BackColorStr == NULL) {
|
|
|
|
|
return ShellStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShellStatus = GetClsColorIndex (BackColorStr, 7, 1, &ColorIndex);
|
|
|
|
|
if (ShellStatus != SHELL_SUCCESS) {
|
|
|
|
|
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", BackColorStr);
|
|
|
|
|
return ShellStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Background = mClsBackgroundColorMap[ColorIndex];
|
|
|
|
|
|
|
|
|
|
if (ForeColorStr != NULL) {
|
|
|
|
|
ShellStatus = GetClsColorIndex (ForeColorStr, 15, 2, &ColorIndex);
|
|
|
|
|
if (ShellStatus != SHELL_SUCCESS) {
|
|
|
|
|
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", ForeColorStr);
|
|
|
|
|
return ShellStatus;
|
2010-09-14 05:18:09 +00:00
|
|
|
}
|
2026-04-28 18:25:08 +02:00
|
|
|
|
|
|
|
|
Foreground = mClsForegroundColorMap[ColorIndex];
|
|
|
|
|
} else {
|
|
|
|
|
//
|
|
|
|
|
// Since foreground color is not modified, so retain
|
|
|
|
|
// existing foreground color without any change to it.
|
|
|
|
|
//
|
|
|
|
|
Foreground = gST->ConOut->Mode->Attribute & 0x0F;
|
2010-09-14 05:18:09 +00:00
|
|
|
}
|
2021-12-05 14:54:13 -08:00
|
|
|
|
2026-04-28 18:25:08 +02:00
|
|
|
Status = gST->ConOut->SetAttribute (gST->ConOut, (Foreground | Background) & 0x7F);
|
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
Status = gST->ConOut->ClearScreen (gST->ConOut);
|
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
2026-04-28 14:53:52 +02:00
|
|
|
return ShellStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Function for 'cls' command.
|
|
|
|
|
|
|
|
|
|
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
|
|
|
|
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
|
|
|
|
**/
|
|
|
|
|
SHELL_STATUS
|
|
|
|
|
EFIAPI
|
|
|
|
|
ShellCommandRunCls (
|
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
LIST_ENTRY *Package;
|
|
|
|
|
CHAR16 *ProblemParam;
|
|
|
|
|
SHELL_STATUS ShellStatus;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Initialize variables
|
|
|
|
|
//
|
|
|
|
|
ShellStatus = SHELL_SUCCESS;
|
|
|
|
|
ProblemParam = NULL;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// initialize the shell lib (we must be in non-auto-init...)
|
|
|
|
|
//
|
|
|
|
|
Status = ShellInitialize ();
|
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// parse the command line
|
|
|
|
|
//
|
|
|
|
|
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
|
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
|
|
|
|
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"cls", ProblemParam);
|
|
|
|
|
FreePool (ProblemParam);
|
|
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
|
} else {
|
|
|
|
|
ASSERT (FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ShellStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShellStatus = MainCmdCls (Package);
|
|
|
|
|
|
2010-09-14 05:18:09 +00:00
|
|
|
//
|
|
|
|
|
// free the command line package
|
|
|
|
|
//
|
|
|
|
|
ShellCommandLineFreeVarList (Package);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// return the status
|
|
|
|
|
//
|
|
|
|
|
return (ShellStatus);
|
|
|
|
|
}
|