]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c
191c1e8eb05dca352593e63ee1336111f3608e85
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Cls.c
1 /** @file
2 Main file for attrib shell level 2 function.
3
4 Copyright (c) 2015, Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved. <BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "UefiShellLevel3CommandsLib.h"
17
18 /**
19 Function for 'cls' command.
20
21 @param[in] ImageHandle Handle to the Image (NULL if Internal).
22 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
23 **/
24 SHELL_STATUS
25 EFIAPI
26 ShellCommandRunCls (
27 IN EFI_HANDLE ImageHandle,
28 IN EFI_SYSTEM_TABLE *SystemTable
29 )
30 {
31 EFI_STATUS Status;
32 LIST_ENTRY *Package;
33 UINTN Background;
34 UINTN ForeColor;
35 CHAR16 *ProblemParam;
36 SHELL_STATUS ShellStatus;
37 CONST CHAR16 *Param1;
38
39 //
40 // Initialize variables
41 //
42 ShellStatus = SHELL_SUCCESS;
43 ProblemParam = NULL;
44 Background = 0;
45
46 //
47 // initialize the shell lib (we must be in non-auto-init...)
48 //
49 Status = ShellInitialize();
50 ASSERT_EFI_ERROR(Status);
51
52 //
53 // parse the command line
54 //
55 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
56 if (EFI_ERROR(Status)) {
57 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
58 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"cls", ProblemParam);
59 FreePool(ProblemParam);
60 ShellStatus = SHELL_INVALID_PARAMETER;
61 } else {
62 ASSERT(FALSE);
63 }
64 } else {
65 //
66 // check for "-?"
67 //
68 if (ShellCommandLineGetFlag(Package, L"-?")) {
69 ASSERT(FALSE);
70 } else {
71 //
72 // If there are 0 value parameters, clear sceen
73 //
74 Param1 = ShellCommandLineGetRawValue(Package, 1);
75 if (Param1 == NULL) {
76 //
77 // clear screen
78 //
79 gST->ConOut->ClearScreen (gST->ConOut);
80 } else if (ShellCommandLineGetCount(Package) > 2) {
81 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"cls");
82 ShellStatus = SHELL_INVALID_PARAMETER;
83 } else {
84 if (ShellStrToUintn(Param1) > 7 || StrLen(Param1) > 1 || !ShellIsDecimalDigitCharacter(*Param1)) {
85 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", Param1);
86 ShellStatus = SHELL_INVALID_PARAMETER;
87 } else {
88 switch (ShellStrToUintn(Param1)) {
89 case 0:
90 Background = EFI_BACKGROUND_BLACK;
91 break;
92 case 1:
93 Background = EFI_BACKGROUND_BLUE;
94 break;
95 case 2:
96 Background = EFI_BACKGROUND_GREEN;
97 break;
98 case 3:
99 Background = EFI_BACKGROUND_CYAN;
100 break;
101 case 4:
102 Background = EFI_BACKGROUND_RED;
103 break;
104 case 5:
105 Background = EFI_BACKGROUND_MAGENTA;
106 break;
107 case 6:
108 Background = EFI_BACKGROUND_BROWN;
109 break;
110 case 7:
111 Background = EFI_BACKGROUND_LIGHTGRAY;
112 break;
113 }
114 ForeColor = (~ShellStrToUintn(Param1)) & 0xF;
115 Status = gST->ConOut->SetAttribute (gST->ConOut, (ForeColor | Background) & 0x7F );
116 ASSERT_EFI_ERROR(Status);
117 Status = gST->ConOut->ClearScreen (gST->ConOut);
118 ASSERT_EFI_ERROR(Status);
119 }
120 }
121 }
122 }
123 //
124 // free the command line package
125 //
126 ShellCommandLineFreeVarList (Package);
127
128 //
129 // return the status
130 //
131 return (ShellStatus);
132 }
133