2 Main file for attrib shell level 2 function.
4 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
5 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
6 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. <BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "UefiShellLevel3CommandsLib.h"
13 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
14 { L
"-sfo", TypeFlag
},
19 Function for 'cls' command.
21 @param[in] ImageHandle Handle to the Image (NULL if Internal).
22 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
27 IN EFI_HANDLE ImageHandle
,
28 IN EFI_SYSTEM_TABLE
*SystemTable
36 SHELL_STATUS ShellStatus
;
37 CONST CHAR16
*BackColorStr
;
38 CONST CHAR16
*ForeColorStr
;
41 // Initialize variables
43 ShellStatus
= SHELL_SUCCESS
;
49 // initialize the shell lib (we must be in non-auto-init...)
51 Status
= ShellInitialize ();
52 ASSERT_EFI_ERROR (Status
);
55 // parse the command line
57 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
58 if (EFI_ERROR (Status
)) {
59 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
60 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel3HiiHandle
, L
"cls", ProblemParam
);
61 FreePool (ProblemParam
);
62 ShellStatus
= SHELL_INVALID_PARAMETER
;
70 if (ShellCommandLineGetFlag (Package
, L
"-?")) {
72 } else if (ShellCommandLineGetFlag (Package
, L
"-sfo")) {
73 if (ShellCommandLineGetCount (Package
) > 1) {
74 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel3HiiHandle
, L
"cls");
75 ShellStatus
= SHELL_INVALID_PARAMETER
;
77 Background
= (gST
->ConOut
->Mode
->Attribute
>> 4) & 0x7;
78 Foreground
= gST
->ConOut
->Mode
->Attribute
& 0x0F;
79 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel3HiiHandle
, L
"cls");
84 STRING_TOKEN (STR_CLS_OUTPUT_SFO
),
85 gShellLevel3HiiHandle
,
86 gST
->ConOut
->Mode
->Attribute
,
93 // If there are 0 value parameters, clear sceen
95 BackColorStr
= ShellCommandLineGetRawValue (Package
, 1);
96 ForeColorStr
= ShellCommandLineGetRawValue (Package
, 2);
98 if ((BackColorStr
== NULL
) && (ForeColorStr
== NULL
)) {
102 gST
->ConOut
->ClearScreen (gST
->ConOut
);
103 } else if (ShellCommandLineGetCount (Package
) > 3) {
104 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel3HiiHandle
, L
"cls");
105 ShellStatus
= SHELL_INVALID_PARAMETER
;
107 if (BackColorStr
!= NULL
) {
108 if ((ShellStrToUintn (BackColorStr
) > 7) || (StrLen (BackColorStr
) > 1) || (!ShellIsDecimalDigitCharacter (*BackColorStr
))) {
109 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel3HiiHandle
, L
"cls", BackColorStr
);
110 ShellStatus
= SHELL_INVALID_PARAMETER
;
112 switch (ShellStrToUintn (BackColorStr
)) {
114 Background
= EFI_BACKGROUND_BLACK
;
117 Background
= EFI_BACKGROUND_BLUE
;
120 Background
= EFI_BACKGROUND_GREEN
;
123 Background
= EFI_BACKGROUND_CYAN
;
126 Background
= EFI_BACKGROUND_RED
;
129 Background
= EFI_BACKGROUND_MAGENTA
;
132 Background
= EFI_BACKGROUND_BROWN
;
135 Background
= EFI_BACKGROUND_LIGHTGRAY
;
139 if (ForeColorStr
!= NULL
) {
140 if ((ShellStrToUintn (ForeColorStr
) > 15) || (StrLen (ForeColorStr
) > 2) || (!ShellIsDecimalDigitCharacter (*ForeColorStr
))) {
141 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel3HiiHandle
, L
"cls", ForeColorStr
);
142 ShellStatus
= SHELL_INVALID_PARAMETER
;
144 switch (ShellStrToUintn (ForeColorStr
)) {
146 Foreground
= EFI_BLACK
;
149 Foreground
= EFI_BLUE
;
152 Foreground
= EFI_GREEN
;
155 Foreground
= EFI_CYAN
;
158 Foreground
= EFI_RED
;
161 Foreground
= EFI_MAGENTA
;
164 Foreground
= EFI_BROWN
;
167 Foreground
= EFI_LIGHTGRAY
;
170 Foreground
= EFI_DARKGRAY
;
173 Foreground
= EFI_LIGHTBLUE
;
176 Foreground
= EFI_LIGHTGREEN
;
179 Foreground
= EFI_LIGHTCYAN
;
182 Foreground
= EFI_LIGHTRED
;
185 Foreground
= EFI_LIGHTMAGENTA
;
188 Foreground
= EFI_YELLOW
;
191 Foreground
= EFI_WHITE
;
197 // Since foreground color is not modified, so retain
198 // existing foreground color without any change to it.
200 Foreground
= gST
->ConOut
->Mode
->Attribute
& 0x0F;
203 if (ShellStatus
== SHELL_SUCCESS
) {
204 Status
= gST
->ConOut
->SetAttribute (gST
->ConOut
, (Foreground
| Background
) & 0x7F);
205 ASSERT_EFI_ERROR (Status
);
206 Status
= gST
->ConOut
->ClearScreen (gST
->ConOut
);
207 ASSERT_EFI_ERROR (Status
);
216 // free the command line package
218 ShellCommandLineFreeVarList (Package
);
223 return (ShellStatus
);