]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ConsoleLogger.c
Enhance Shell 2.0 to not depend on keyboard driver implementation to fix the "CTRL...
[mirror_edk2.git] / ShellPkg / Application / Shell / ConsoleLogger.c
index 58518cabe94238afd230c1b172c6093fba06759e..6f7ed95a611ebec13cf6417e0919ada3cc0ee652 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Provides interface to shell console logger.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2013 Hewlett-Packard Development Company, L.P.\r
+  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 **/\r
 \r
-#include "ConsoleLogger.h"\r
 #include "Shell.h"\r
 \r
-STATIC CONST CHAR16                     mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
-\r
 /**\r
   Install our intermediate ConOut into the system table to\r
   keep a log of all the info that is displayed to the user.\r
@@ -258,10 +256,12 @@ UpdateDisplayFromHistory(
   CHAR16          *StringSegment;\r
   CHAR16          *StringSegmentEnd;\r
   CHAR16          StringSegmentEndChar;\r
+  INT32           OrigAttribute;\r
 \r
   ASSERT(ConsoleInfo != NULL);\r
   TempCharHolder = CHAR_NULL;\r
   RetVal = EFI_SUCCESS;\r
+  OrigAttribute = ConsoleInfo->OldConOut->Mode->Attribute;\r
 \r
   //\r
   // Disable cursor visibility and move it to the top left corner\r
@@ -369,6 +369,11 @@ UpdateDisplayFromHistory(
     if (EFI_ERROR (Status)) {\r
       RetVal = Status;\r
     }\r
+  } else {\r
+    ConsoleInfo->OldConOut->SetAttribute (\r
+                                ConsoleInfo->OldConOut,\r
+                                OrigAttribute\r
+                               );\r
   }\r
 \r
   return (RetVal);\r
@@ -466,7 +471,7 @@ AppendStringToHistory(
             ; Index < ConsoleInfo->ColsPerScreen\r
             ; Index++\r
            ){\r
-          *(ConsoleInfo->Attributes + (CopySize/sizeof(ConsoleInfo->Attributes)) + Index) = ConsoleInfo->HistoryMode.Attribute;\r
+          *(ConsoleInfo->Attributes + (CopySize/sizeof(ConsoleInfo->Attributes[0])) + Index) = ConsoleInfo->HistoryMode.Attribute;\r
         }\r
 \r
         //\r
@@ -636,6 +641,10 @@ ConsoleLoggerDoPageBreak(
   } else if (*Resp == ShellPromptResponseQuit) {\r
     FreePool(Resp);\r
     ShellInfoObject.ConsoleInfo->Enabled = FALSE;\r
+    //\r
+    // When user wants to quit, the shell should stop running the command.\r
+    //\r
+    gBS->SignalEvent (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak);\r
     return (EFI_DEVICE_ERROR);\r
   } else {\r
     ASSERT(FALSE);\r
@@ -729,7 +738,7 @@ ConsoleLoggerPrintWithPageBreak(
       //\r
       // check if that is the last column\r
       //\r
-      if ((INTN)ConsoleInfo->ColsPerScreen == ConsoleInfo->OurConOut.Mode->CursorColumn - 1) {\r
+      if ((INTN)ConsoleInfo->ColsPerScreen == ConsoleInfo->OurConOut.Mode->CursorColumn + 1) {\r
         //\r
         // output a line similar to the linefeed character.\r
         //\r
@@ -753,7 +762,7 @@ ConsoleLoggerPrintWithPageBreak(
         //\r
         // Update LineStart Variable\r
         //\r
-        LineStart = Walker;\r
+        LineStart = Walker + 1;\r
 \r
         //\r
         // increment row count and zero the column\r
@@ -810,12 +819,41 @@ ConsoleLoggerOutputString (
   IN  CHAR16                          *WString\r
   )\r
 {\r
-  CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r
+  EFI_STATUS                        Status;\r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r
+  EFI_KEY_DATA                      KeyData;\r
+  UINTN                             EventIndex;\r
+  CONSOLE_LOGGER_PRIVATE_DATA       *ConsoleInfo;\r
+\r
   ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r
   if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {\r
     return (EFI_UNSUPPORTED);\r
   }\r
   ASSERT(ShellInfoObject.ConsoleInfo == ConsoleInfo);\r
+\r
+  Status = gBS->HandleProtocol (gST->ConsoleInHandle, &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);\r
+  if (!EFI_ERROR (Status)) {\r
+    while (ShellInfoObject.HaltOutput) {\r
+\r
+      ShellInfoObject.HaltOutput = FALSE;\r
+      //\r
+      // just get some key\r
+      //\r
+      Status = gBS->WaitForEvent (1, &TxtInEx->WaitForKeyEx, &EventIndex);\r
+      ASSERT_EFI_ERROR (Status);\r
+      Status = TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData);\r
+      ASSERT_EFI_ERROR (Status);\r
+\r
+      if ((KeyData.Key.UnicodeChar == L's') && (KeyData.Key.ScanCode == SCAN_NULL) &&\r
+          ((KeyData.KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID | EFI_LEFT_CONTROL_PRESSED)) ||\r
+           (KeyData.KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID | EFI_RIGHT_CONTROL_PRESSED))\r
+          )\r
+         ) {\r
+        ShellInfoObject.HaltOutput = TRUE;\r
+      }\r
+    }\r
+  }\r
+\r
   if (!ShellInfoObject.ConsoleInfo->Enabled) {\r
     return (EFI_DEVICE_ERROR);\r
   } else if (ShellInfoObject.PageBreakEnabled) {\r
@@ -1011,7 +1049,7 @@ ConsoleLoggerClearScreen (
   // Record console output history\r
   //\r
   if (!EFI_ERROR (Status)) {\r
-    Screen = &ConsoleInfo->Buffer[(ConsoleInfo->ColsPerScreen + 1) * ConsoleInfo->CurrentStartRow];\r
+    Screen = &ConsoleInfo->Buffer[(ConsoleInfo->ColsPerScreen + 2) * ConsoleInfo->CurrentStartRow];\r
     Attributes = &ConsoleInfo->Attributes[ConsoleInfo->ColsPerScreen * ConsoleInfo->CurrentStartRow];\r
     for ( Row = ConsoleInfo->OriginalStartRow\r
         ; Row < (ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount)\r
@@ -1029,7 +1067,7 @@ ConsoleLoggerClearScreen (
       //\r
       // Skip the NULL on each column end in text buffer only\r
       //\r
-      Screen++;\r
+      Screen += 2;\r
     }\r
     ConsoleInfo->HistoryMode.CursorColumn = 0;\r
     ConsoleInfo->HistoryMode.CursorRow    = 0;\r