]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Enhance 'cls' command to change the background and foreground colors
authorTapan Shah <tapandshah@hpe.com>
Fri, 23 Sep 2016 16:03:16 +0000 (09:03 -0700)
committerJaben Carsey <jaben.carsey@intel.com>
Mon, 26 Sep 2016 20:10:31 +0000 (13:10 -0700)
As per ECR 1416 change in UEFI Shell Specification 2.2,
enhancing 'cls' command to change the background color as well as
foreground color. Also add support to display current settings
using 'cls -sfo' command.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Tapan Shah <tapandshah@hpe.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c
ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.uni

index 61b9ef854e5c532732cc28f2730595f75cad6935..de79b825db8ef1e2b411928f0a05831dd50238db 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
   Main file for attrib shell level 2 function.\r
 \r
+  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
   Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved. <BR>\r
   This program and the accompanying materials\r
 \r
 #include "UefiShellLevel3CommandsLib.h"\r
 \r
+STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
+  {L"-sfo", TypeFlag},\r
+  {NULL,    TypeMax}\r
+  };\r
+\r
 /**\r
   Function for 'cls' command.\r
 \r
@@ -31,10 +37,11 @@ ShellCommandRunCls (
   EFI_STATUS    Status;\r
   LIST_ENTRY    *Package;\r
   UINTN         Background;\r
-  UINTN         ForeColor;\r
+  UINTN         Foreground;\r
   CHAR16        *ProblemParam;\r
   SHELL_STATUS  ShellStatus;\r
-  CONST CHAR16  *Param1;\r
+  CONST CHAR16  *BackColorStr;\r
+  CONST CHAR16  *ForeColorStr;\r
 \r
   //\r
   // Initialize variables\r
@@ -42,6 +49,7 @@ ShellCommandRunCls (
   ShellStatus   = SHELL_SUCCESS;\r
   ProblemParam  = NULL;\r
   Background    = 0;\r
+  Foreground    = 0;\r
 \r
   //\r
   // initialize the shell lib (we must be in non-auto-init...)\r
@@ -52,7 +60,7 @@ ShellCommandRunCls (
   //\r
   // parse the command line\r
   //\r
-  Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);\r
+  Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
   if (EFI_ERROR(Status)) {\r
     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"cls", ProblemParam);  \r
@@ -67,55 +75,143 @@ ShellCommandRunCls (
     //\r
     if (ShellCommandLineGetFlag(Package, L"-?")) {\r
       ASSERT(FALSE);\r
+    } else if (ShellCommandLineGetFlag (Package, L"-sfo")) {\r
+      if (ShellCommandLineGetCount (Package) > 1) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"cls");\r
+        ShellStatus = SHELL_INVALID_PARAMETER;\r
+      } else {\r
+        Background = (gST->ConOut->Mode->Attribute >> 4) & 0x7;\r
+        Foreground = gST->ConOut->Mode->Attribute & 0x0F;\r
+        ShellPrintHiiEx (\r
+          -1,\r
+          -1,\r
+          NULL,\r
+          STRING_TOKEN (STR_CLS_OUTPUT_SFO),\r
+          gShellLevel3HiiHandle,\r
+          gST->ConOut->Mode->Attribute,\r
+          Foreground,\r
+          Background\r
+          );\r
+      }\r
     } else {\r
       //\r
       // If there are 0 value parameters, clear sceen\r
       //\r
-      Param1 = ShellCommandLineGetRawValue(Package, 1);\r
-      if (Param1 == NULL) {\r
+      BackColorStr = ShellCommandLineGetRawValue (Package, 1);\r
+      ForeColorStr = ShellCommandLineGetRawValue (Package, 2);\r
+\r
+      if (BackColorStr == NULL && ForeColorStr == NULL) {\r
         //\r
         // clear screen\r
         //\r
         gST->ConOut->ClearScreen (gST->ConOut);\r
-      } else if (ShellCommandLineGetCount(Package) > 2) {\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"cls");  \r
+      } else if (ShellCommandLineGetCount (Package) > 3) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"cls");\r
         ShellStatus = SHELL_INVALID_PARAMETER;\r
       } else {\r
-        if (ShellStrToUintn(Param1) > 7 || StrLen(Param1) > 1 || !ShellIsDecimalDigitCharacter(*Param1)) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", Param1);  \r
-          ShellStatus = SHELL_INVALID_PARAMETER;\r
-        } else {\r
-          switch (ShellStrToUintn(Param1)) {\r
-            case 0:\r
-              Background = EFI_BACKGROUND_BLACK;\r
-              break;\r
-            case 1:\r
-              Background = EFI_BACKGROUND_BLUE;\r
-              break;\r
-            case 2:\r
-              Background = EFI_BACKGROUND_GREEN;\r
-              break;\r
-            case 3:\r
-              Background = EFI_BACKGROUND_CYAN;\r
-              break;\r
-            case 4:\r
-              Background = EFI_BACKGROUND_RED;\r
-              break;\r
-            case 5:\r
-              Background = EFI_BACKGROUND_MAGENTA;\r
-              break;\r
-            case 6:\r
-              Background = EFI_BACKGROUND_BROWN;\r
-              break;\r
-            case 7:\r
-              Background = EFI_BACKGROUND_LIGHTGRAY;\r
-              break;\r
+        if (BackColorStr != NULL) {\r
+          if ((ShellStrToUintn (BackColorStr) > 7) || (StrLen (BackColorStr) > 1) || (!ShellIsDecimalDigitCharacter (*BackColorStr))) {\r
+            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", BackColorStr);\r
+            ShellStatus = SHELL_INVALID_PARAMETER;\r
+          } else {\r
+            switch (ShellStrToUintn (BackColorStr)) {\r
+              case 0:\r
+                Background = EFI_BACKGROUND_BLACK;\r
+                break;\r
+              case 1:\r
+                Background = EFI_BACKGROUND_BLUE;\r
+                break;\r
+              case 2:\r
+                Background = EFI_BACKGROUND_GREEN;\r
+                break;\r
+              case 3:\r
+                Background = EFI_BACKGROUND_CYAN;\r
+                break;\r
+              case 4:\r
+                Background = EFI_BACKGROUND_RED;\r
+                break;\r
+              case 5:\r
+                Background = EFI_BACKGROUND_MAGENTA;\r
+                break;\r
+              case 6:\r
+                Background = EFI_BACKGROUND_BROWN;\r
+                break;\r
+              case 7:\r
+                Background = EFI_BACKGROUND_LIGHTGRAY;\r
+                break;\r
+            }\r
+\r
+            if (ForeColorStr != NULL) {\r
+              if ((ShellStrToUintn (ForeColorStr) > 15) || (StrLen (ForeColorStr) > 2) || (!ShellIsDecimalDigitCharacter (*ForeColorStr))) {\r
+                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", ForeColorStr);\r
+                ShellStatus = SHELL_INVALID_PARAMETER;\r
+              } else {\r
+                switch (ShellStrToUintn (ForeColorStr)) {\r
+                  case 0:\r
+                    Foreground = EFI_BLACK;\r
+                    break;\r
+                  case 1:\r
+                    Foreground = EFI_BLUE;\r
+                    break;\r
+                  case 2:\r
+                    Foreground = EFI_GREEN;\r
+                    break;\r
+                  case 3:\r
+                    Foreground = EFI_CYAN;\r
+                    break;\r
+                  case 4:\r
+                    Foreground = EFI_RED;\r
+                    break;\r
+                  case 5:\r
+                    Foreground = EFI_MAGENTA;\r
+                    break;\r
+                  case 6:\r
+                    Foreground = EFI_BROWN;\r
+                    break;\r
+                  case 7:\r
+                    Foreground = EFI_LIGHTGRAY;\r
+                    break;\r
+                  case 8:\r
+                    Foreground = EFI_DARKGRAY;\r
+                    break;\r
+                  case 9:\r
+                    Foreground = EFI_LIGHTBLUE;\r
+                    break;\r
+                  case 10:\r
+                    Foreground = EFI_LIGHTGREEN;\r
+                    break;\r
+                  case 11:\r
+                    Foreground = EFI_LIGHTCYAN;\r
+                    break;\r
+                  case 12:\r
+                    Foreground = EFI_LIGHTRED;\r
+                    break;\r
+                  case 13:\r
+                    Foreground = EFI_LIGHTMAGENTA;\r
+                    break;\r
+                  case 14:\r
+                    Foreground = EFI_YELLOW;\r
+                    break;\r
+                  case 15:\r
+                    Foreground = EFI_WHITE;\r
+                    break;\r
+                }\r
+              }\r
+            } else {\r
+              //\r
+              // Since foreground color is not modified, so retain\r
+              // existing foreground color without any change to it.\r
+              //\r
+              Foreground = gST->ConOut->Mode->Attribute & 0x0F;\r
+            }\r
+\r
+            if (ShellStatus == SHELL_SUCCESS) {\r
+              Status = gST->ConOut->SetAttribute (gST->ConOut, (Foreground | Background) & 0x7F);\r
+              ASSERT_EFI_ERROR (Status);\r
+              Status = gST->ConOut->ClearScreen (gST->ConOut);\r
+              ASSERT_EFI_ERROR (Status);\r
+            }\r
           }\r
-          ForeColor = (~ShellStrToUintn(Param1)) & 0xF;\r
-          Status = gST->ConOut->SetAttribute (gST->ConOut, (ForeColor | Background) & 0x7F );\r
-          ASSERT_EFI_ERROR(Status);\r
-          Status = gST->ConOut->ClearScreen (gST->ConOut);\r
-          ASSERT_EFI_ERROR(Status);\r
         }\r
       }\r
     }\r
index fc9c5d447ccc3a13fd69862f9e2eed847c9cfa0d..bbcb752ac06e58afea3fe71539225195769c880f 100644 (file)
@@ -1,5 +1,6 @@
 // /**\r
 //\r
+// (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 // (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
 // Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved. <BR>\r
 // This program and the accompanying materials\r
@@ -82,6 +83,7 @@
 #string STR_ALIAS_OUTPUT          #language en-US "%1c %10s:%s\r\n"\r
 \r
 #string STR_GET_MTC_OUTPUT        #language en-US "%016Lx\r\n"\r
+#string STR_CLS_OUTPUT_SFO        #language en-US "ConOutAttribInfo,"%d","%d","%d"\r\n"\r
 \r
 #string STR_GET_HELP_HELP         #language en-US ""\r
 ".TH help 0 "Displays help information from the UEFI Shell."\r\n"\r
 #string STR_GET_HELP_CLS          #language en-US ""\r
 ".TH cls 0 "clear screen"\r\n"\r
 ".SH NAME\r\n"\r
-"Clears standard output and optionally changes background color.\r\n"\r
+"Clears the console output and optionally changes the background and foreground color.\r\n"\r
 ".SH SYNOPSIS\r\n"\r
 " \r\n"\r
-"CLS [color]\r\n"\r
+"CLS [background] [foreground] | [-sfo]\r\n"\r
 ".SH OPTIONS\r\n"\r
 " \r\n"\r
-"  color - Sets a new background color:\r\n"\r
-"            0 - Black\r\n"\r
-"            1 - Blue\r\n"\r
-"            2 - Green\r\n"\r
-"            3 - Cyan\r\n"\r
-"            4 - Red\r\n"\r
-"            5 - Magenta\r\n"\r
-"            6 - Yellow\r\n"\r
-"            7 - Light gray\r\n"\r
+"  background - Sets a new background color:\r\n"\r
+"               0 - Black\r\n"\r
+"               1 - Blue\r\n"\r
+"               2 - Green\r\n"\r
+"               3 - Cyan\r\n"\r
+"               4 - Red\r\n"\r
+"               5 - Magenta\r\n"\r
+"               6 - Yellow\r\n"\r
+"               7 - Light gray\r\n"\r
+"  foreground - Sets a new foreground color:\r\n"\r
+"               0  - Black\r\n"\r
+"               1  - Blue\r\n"\r
+"               2  - Green\r\n"\r
+"               3  - Cyan\r\n"\r
+"               4  - Red\r\n"\r
+"               5  - Magenta\r\n"\r
+"               6  - Yellow\r\n"\r
+"               7  - Light gray\r\n"\r
+"               8  - Dark gray\r\n"\r
+"               9  - Light blue\r\n"\r
+"               10 - Light green\r\n"\r
+"               11 - Light cyan\r\n"\r
+"               12 - Light red\r\n"\r
+"               13 - Light magenta\r\n"\r
+"               14 - Yellow\r\n"\r
+"               15 - White\r\n"\r
+"  -sfo       - Displays current console color settings in Standard Format\r\n"\r
+"               Output.\r\n"\r
 ".SH DESCRIPTION\r\n"\r
 " \r\n"\r
 "NOTES:\r\n"\r
 "  1. This command clears the standard output device with an optional\r\n"\r
-"     background color attribute. If a color is not specified, then the\r\n"\r
-"     background color does not change.\r\n"\r
+"     background and foreground color attribute.\r\n"\r
+"  2. If background color is not specified, or if background and foreground\r\n"\r
+"     colors are not specified, then the colors do not change.\r\n"\r
+"  3. When -sfo flag is used, console output is not cleared and instead it\r\n"\r
+"     displays current console foreground and background attribute settings.\r\n"\r
 ".SH EXAMPLES\r\n"\r
 " \r\n"\r
 "EXAMPLES:\r\n"\r
-"  * To clear standard output without changing the background color:\r\n"\r
+"  * To clear standard output without changing the background or foreground\r\n"\r
+"    color:\r\n"\r
 "    fs0:\> cls\r\n"\r
 " \r\n"\r
 "  * To clear standard output and change the background color to cyan:\r\n"\r
 "    fs0:\> cls 3\r\n"\r
 " \r\n"\r
-"  * To clear standard output and change the background to the default color:\r\n"\r
-"    fs0:\> cls 0\r\n"\r
+"  * To clear standard output and change the background to black and foreground\r\n"\r
+"    to white:\r\n"\r
+"    fs0:\> cls 0 15\r\n"\r
 ".SH RETURNVALUES\r\n"\r
 " \r\n"\r
 "RETURN VALUES:\r\n"\r