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 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "UefiShellLevel3CommandsLib.h"
19 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
25 Function for 'cls' command.
27 @param[in] ImageHandle Handle to the Image (NULL if Internal).
28 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
33 IN EFI_HANDLE ImageHandle
,
34 IN EFI_SYSTEM_TABLE
*SystemTable
42 SHELL_STATUS ShellStatus
;
43 CONST CHAR16
*BackColorStr
;
44 CONST CHAR16
*ForeColorStr
;
47 // Initialize variables
49 ShellStatus
= SHELL_SUCCESS
;
55 // initialize the shell lib (we must be in non-auto-init...)
57 Status
= ShellInitialize();
58 ASSERT_EFI_ERROR(Status
);
61 // parse the command line
63 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
64 if (EFI_ERROR(Status
)) {
65 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
66 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel3HiiHandle
, L
"cls", ProblemParam
);
67 FreePool(ProblemParam
);
68 ShellStatus
= SHELL_INVALID_PARAMETER
;
76 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
78 } else if (ShellCommandLineGetFlag (Package
, L
"-sfo")) {
79 if (ShellCommandLineGetCount (Package
) > 1) {
80 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel3HiiHandle
, L
"cls");
81 ShellStatus
= SHELL_INVALID_PARAMETER
;
83 Background
= (gST
->ConOut
->Mode
->Attribute
>> 4) & 0x7;
84 Foreground
= gST
->ConOut
->Mode
->Attribute
& 0x0F;
85 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel3HiiHandle
, L
"cls");
90 STRING_TOKEN (STR_CLS_OUTPUT_SFO
),
91 gShellLevel3HiiHandle
,
92 gST
->ConOut
->Mode
->Attribute
,
99 // If there are 0 value parameters, clear sceen
101 BackColorStr
= ShellCommandLineGetRawValue (Package
, 1);
102 ForeColorStr
= ShellCommandLineGetRawValue (Package
, 2);
104 if (BackColorStr
== NULL
&& ForeColorStr
== NULL
) {
108 gST
->ConOut
->ClearScreen (gST
->ConOut
);
109 } else if (ShellCommandLineGetCount (Package
) > 3) {
110 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel3HiiHandle
, L
"cls");
111 ShellStatus
= SHELL_INVALID_PARAMETER
;
113 if (BackColorStr
!= NULL
) {
114 if ((ShellStrToUintn (BackColorStr
) > 7) || (StrLen (BackColorStr
) > 1) || (!ShellIsDecimalDigitCharacter (*BackColorStr
))) {
115 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel3HiiHandle
, L
"cls", BackColorStr
);
116 ShellStatus
= SHELL_INVALID_PARAMETER
;
118 switch (ShellStrToUintn (BackColorStr
)) {
120 Background
= EFI_BACKGROUND_BLACK
;
123 Background
= EFI_BACKGROUND_BLUE
;
126 Background
= EFI_BACKGROUND_GREEN
;
129 Background
= EFI_BACKGROUND_CYAN
;
132 Background
= EFI_BACKGROUND_RED
;
135 Background
= EFI_BACKGROUND_MAGENTA
;
138 Background
= EFI_BACKGROUND_BROWN
;
141 Background
= EFI_BACKGROUND_LIGHTGRAY
;
145 if (ForeColorStr
!= NULL
) {
146 if ((ShellStrToUintn (ForeColorStr
) > 15) || (StrLen (ForeColorStr
) > 2) || (!ShellIsDecimalDigitCharacter (*ForeColorStr
))) {
147 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel3HiiHandle
, L
"cls", ForeColorStr
);
148 ShellStatus
= SHELL_INVALID_PARAMETER
;
150 switch (ShellStrToUintn (ForeColorStr
)) {
152 Foreground
= EFI_BLACK
;
155 Foreground
= EFI_BLUE
;
158 Foreground
= EFI_GREEN
;
161 Foreground
= EFI_CYAN
;
164 Foreground
= EFI_RED
;
167 Foreground
= EFI_MAGENTA
;
170 Foreground
= EFI_BROWN
;
173 Foreground
= EFI_LIGHTGRAY
;
176 Foreground
= EFI_DARKGRAY
;
179 Foreground
= EFI_LIGHTBLUE
;
182 Foreground
= EFI_LIGHTGREEN
;
185 Foreground
= EFI_LIGHTCYAN
;
188 Foreground
= EFI_LIGHTRED
;
191 Foreground
= EFI_LIGHTMAGENTA
;
194 Foreground
= EFI_YELLOW
;
197 Foreground
= EFI_WHITE
;
203 // Since foreground color is not modified, so retain
204 // existing foreground color without any change to it.
206 Foreground
= gST
->ConOut
->Mode
->Attribute
& 0x0F;
209 if (ShellStatus
== SHELL_SUCCESS
) {
210 Status
= gST
->ConOut
->SetAttribute (gST
->ConOut
, (Foreground
| Background
) & 0x7F);
211 ASSERT_EFI_ERROR (Status
);
212 Status
= gST
->ConOut
->ClearScreen (gST
->ConOut
);
213 ASSERT_EFI_ERROR (Status
);
221 // free the command line package
223 ShellCommandLineFreeVarList (Package
);
228 return (ShellStatus
);