]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOut.c
EmbeddedPkg/SimpleTextInOutSerial: Update the cursor position
[mirror_edk2.git] / EmbeddedPkg / SimpleTextInOutSerial / SimpleTextInOut.c
index bdc67fbda03241b4bc00dd0e8ceb26b180ee064a..85bb08d682eac288f8f1e8d380de11189071cd01 100644 (file)
@@ -1,9 +1,9 @@
 /** @file\r
   Simple Console that sits on a SerialLib. \r
 \r
-  Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
   \r
-  All rights reserved. This program and the accompanying materials\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
   http://opensource.org/licenses/bsd-license.php\r
@@ -517,14 +517,72 @@ OutputString (
   IN CHAR16                           *String\r
   )\r
 {\r
-  UINTN Size          = StrLen(String) + 1;\r
-  CHAR8 *OutputString = AllocatePool(Size);\r
+  UINTN                       Size;\r
+  CHAR8*                      OutputString;\r
+  EFI_STATUS                  Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode;\r
+  UINTN                       MaxColumn;\r
+  UINTN                       MaxRow;\r
   \r
+  Size = StrLen(String) + 1;\r
+  OutputString = AllocatePool(Size);\r
+\r
   //If there is any non-ascii characters in String buffer then replace it with '?'\r
   //Eventually, UnicodeStrToAsciiStr API should be fixed.\r
   SafeUnicodeStrToAsciiStr(String, OutputString);  \r
   SerialPortWrite ((UINT8 *)OutputString, Size - 1);\r
 \r
+  //\r
+  // Parse each character of the string to output\r
+  // to update the cursor position information\r
+  //\r
+  Mode = This->Mode;\r
+\r
+  Status = This->QueryMode (\r
+                   This,\r
+                   Mode->Mode,\r
+                   &MaxColumn,\r
+                   &MaxRow\r
+                   );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  for (; *String != CHAR_NULL; String++) {\r
+\r
+    switch (*String) {\r
+    case CHAR_BACKSPACE:\r
+      if (Mode->CursorColumn > 0) {\r
+        Mode->CursorColumn--;\r
+      }\r
+      break;\r
+\r
+    case CHAR_LINEFEED:\r
+      if (Mode->CursorRow < (INT32) (MaxRow - 1)) {\r
+        Mode->CursorRow++;\r
+      }\r
+      break;\r
+\r
+    case CHAR_CARRIAGE_RETURN:\r
+      Mode->CursorColumn = 0;\r
+      break;\r
+\r
+    default:\r
+      if (Mode->CursorColumn >= (INT32) (MaxColumn - 1)) {\r
+        // Move the cursor as if we print CHAR_CARRIAGE_RETURN & CHAR_LINE_FEED\r
+        // CHAR_LINEFEED\r
+        if (Mode->CursorRow < (INT32) (MaxRow - 1)) {\r
+          Mode->CursorRow++;\r
+        }\r
+        // CHAR_CARIAGE_RETURN\r
+        Mode->CursorColumn = 0;\r
+      } else {\r
+        Mode->CursorColumn++;\r
+      }\r
+      break;\r
+    }\r
+  }\r
+\r
   FreePool(OutputString);\r
 \r
   return EFI_SUCCESS;\r