]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c
ShellPkg/Application: Fix ">v" cannot update environment variable
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Cls.c
1 /** @file
2 Main file for attrib shell level 2 function.
3
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
11
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.
14
15 **/
16
17 #include "UefiShellLevel3CommandsLib.h"
18
19 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
20 {L"-sfo", TypeFlag},
21 {NULL, TypeMax}
22 };
23
24 /**
25 Function for 'cls' command.
26
27 @param[in] ImageHandle Handle to the Image (NULL if Internal).
28 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
29 **/
30 SHELL_STATUS
31 EFIAPI
32 ShellCommandRunCls (
33 IN EFI_HANDLE ImageHandle,
34 IN EFI_SYSTEM_TABLE *SystemTable
35 )
36 {
37 EFI_STATUS Status;
38 LIST_ENTRY *Package;
39 UINTN Background;
40 UINTN Foreground;
41 CHAR16 *ProblemParam;
42 SHELL_STATUS ShellStatus;
43 CONST CHAR16 *BackColorStr;
44 CONST CHAR16 *ForeColorStr;
45
46 //
47 // Initialize variables
48 //
49 ShellStatus = SHELL_SUCCESS;
50 ProblemParam = NULL;
51 Background = 0;
52 Foreground = 0;
53
54 //
55 // initialize the shell lib (we must be in non-auto-init...)
56 //
57 Status = ShellInitialize();
58 ASSERT_EFI_ERROR(Status);
59
60 //
61 // parse the command line
62 //
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;
69 } else {
70 ASSERT(FALSE);
71 }
72 } else {
73 //
74 // check for "-?"
75 //
76 if (ShellCommandLineGetFlag(Package, L"-?")) {
77 ASSERT(FALSE);
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;
82 } else {
83 Background = (gST->ConOut->Mode->Attribute >> 4) & 0x7;
84 Foreground = gST->ConOut->Mode->Attribute & 0x0F;
85 ShellPrintHiiEx (
86 -1,
87 -1,
88 NULL,
89 STRING_TOKEN (STR_CLS_OUTPUT_SFO),
90 gShellLevel3HiiHandle,
91 gST->ConOut->Mode->Attribute,
92 Foreground,
93 Background
94 );
95 }
96 } else {
97 //
98 // If there are 0 value parameters, clear sceen
99 //
100 BackColorStr = ShellCommandLineGetRawValue (Package, 1);
101 ForeColorStr = ShellCommandLineGetRawValue (Package, 2);
102
103 if (BackColorStr == NULL && ForeColorStr == NULL) {
104 //
105 // clear screen
106 //
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;
111 } else {
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;
116 } else {
117 switch (ShellStrToUintn (BackColorStr)) {
118 case 0:
119 Background = EFI_BACKGROUND_BLACK;
120 break;
121 case 1:
122 Background = EFI_BACKGROUND_BLUE;
123 break;
124 case 2:
125 Background = EFI_BACKGROUND_GREEN;
126 break;
127 case 3:
128 Background = EFI_BACKGROUND_CYAN;
129 break;
130 case 4:
131 Background = EFI_BACKGROUND_RED;
132 break;
133 case 5:
134 Background = EFI_BACKGROUND_MAGENTA;
135 break;
136 case 6:
137 Background = EFI_BACKGROUND_BROWN;
138 break;
139 case 7:
140 Background = EFI_BACKGROUND_LIGHTGRAY;
141 break;
142 }
143
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;
148 } else {
149 switch (ShellStrToUintn (ForeColorStr)) {
150 case 0:
151 Foreground = EFI_BLACK;
152 break;
153 case 1:
154 Foreground = EFI_BLUE;
155 break;
156 case 2:
157 Foreground = EFI_GREEN;
158 break;
159 case 3:
160 Foreground = EFI_CYAN;
161 break;
162 case 4:
163 Foreground = EFI_RED;
164 break;
165 case 5:
166 Foreground = EFI_MAGENTA;
167 break;
168 case 6:
169 Foreground = EFI_BROWN;
170 break;
171 case 7:
172 Foreground = EFI_LIGHTGRAY;
173 break;
174 case 8:
175 Foreground = EFI_DARKGRAY;
176 break;
177 case 9:
178 Foreground = EFI_LIGHTBLUE;
179 break;
180 case 10:
181 Foreground = EFI_LIGHTGREEN;
182 break;
183 case 11:
184 Foreground = EFI_LIGHTCYAN;
185 break;
186 case 12:
187 Foreground = EFI_LIGHTRED;
188 break;
189 case 13:
190 Foreground = EFI_LIGHTMAGENTA;
191 break;
192 case 14:
193 Foreground = EFI_YELLOW;
194 break;
195 case 15:
196 Foreground = EFI_WHITE;
197 break;
198 }
199 }
200 } else {
201 //
202 // Since foreground color is not modified, so retain
203 // existing foreground color without any change to it.
204 //
205 Foreground = gST->ConOut->Mode->Attribute & 0x0F;
206 }
207
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);
213 }
214 }
215 }
216 }
217 }
218 }
219 //
220 // free the command line package
221 //
222 ShellCommandLineFreeVarList (Package);
223
224 //
225 // return the status
226 //
227 return (ShellStatus);
228 }
229