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 - 2014, 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;
89 STRING_TOKEN (STR_CLS_OUTPUT_SFO
),
90 gShellLevel3HiiHandle
,
91 gST
->ConOut
->Mode
->Attribute
,
98 // If there are 0 value parameters, clear sceen
100 BackColorStr
= ShellCommandLineGetRawValue (Package
, 1);
101 ForeColorStr
= ShellCommandLineGetRawValue (Package
, 2);
103 if (BackColorStr
== NULL
&& ForeColorStr
== NULL
) {
107 gST
->ConOut
->ClearScreen (gST
->ConOut
);
108 } else if (ShellCommandLineGetCount (Package
) > 3) {
109 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel3HiiHandle
, L
"cls");
110 ShellStatus
= SHELL_INVALID_PARAMETER
;
112 if (BackColorStr
!= NULL
) {
113 if ((ShellStrToUintn (BackColorStr
) > 7) || (StrLen (BackColorStr
) > 1) || (!ShellIsDecimalDigitCharacter (*BackColorStr
))) {
114 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel3HiiHandle
, L
"cls", BackColorStr
);
115 ShellStatus
= SHELL_INVALID_PARAMETER
;
117 switch (ShellStrToUintn (BackColorStr
)) {
119 Background
= EFI_BACKGROUND_BLACK
;
122 Background
= EFI_BACKGROUND_BLUE
;
125 Background
= EFI_BACKGROUND_GREEN
;
128 Background
= EFI_BACKGROUND_CYAN
;
131 Background
= EFI_BACKGROUND_RED
;
134 Background
= EFI_BACKGROUND_MAGENTA
;
137 Background
= EFI_BACKGROUND_BROWN
;
140 Background
= EFI_BACKGROUND_LIGHTGRAY
;
144 if (ForeColorStr
!= NULL
) {
145 if ((ShellStrToUintn (ForeColorStr
) > 15) || (StrLen (ForeColorStr
) > 2) || (!ShellIsDecimalDigitCharacter (*ForeColorStr
))) {
146 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel3HiiHandle
, L
"cls", ForeColorStr
);
147 ShellStatus
= SHELL_INVALID_PARAMETER
;
149 switch (ShellStrToUintn (ForeColorStr
)) {
151 Foreground
= EFI_BLACK
;
154 Foreground
= EFI_BLUE
;
157 Foreground
= EFI_GREEN
;
160 Foreground
= EFI_CYAN
;
163 Foreground
= EFI_RED
;
166 Foreground
= EFI_MAGENTA
;
169 Foreground
= EFI_BROWN
;
172 Foreground
= EFI_LIGHTGRAY
;
175 Foreground
= EFI_DARKGRAY
;
178 Foreground
= EFI_LIGHTBLUE
;
181 Foreground
= EFI_LIGHTGREEN
;
184 Foreground
= EFI_LIGHTCYAN
;
187 Foreground
= EFI_LIGHTRED
;
190 Foreground
= EFI_LIGHTMAGENTA
;
193 Foreground
= EFI_YELLOW
;
196 Foreground
= EFI_WHITE
;
202 // Since foreground color is not modified, so retain
203 // existing foreground color without any change to it.
205 Foreground
= gST
->ConOut
->Mode
->Attribute
& 0x0F;
208 if (ShellStatus
== SHELL_SUCCESS
) {
209 Status
= gST
->ConOut
->SetAttribute (gST
->ConOut
, (Foreground
| Background
) & 0x7F);
210 ASSERT_EFI_ERROR (Status
);
211 Status
= gST
->ConOut
->ClearScreen (gST
->ConOut
);
212 ASSERT_EFI_ERROR (Status
);
220 // free the command line package
222 ShellCommandLineFreeVarList (Package
);
227 return (ShellStatus
);