From 56226bf769a9eb7712b5627b316ec3898efdd4b4 Mon Sep 17 00:00:00 2001 From: oliviermartin Date: Fri, 3 Jun 2011 09:11:55 +0000 Subject: [PATCH] EmbeddedPkg/SimpleTextInOutSerial: Update the cursor position It is a UEFI requirement to update the cursor position infomation for each string displayed using calls to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL->OutputString(). git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11728 6f19259b-4bc3-4df7-8a09-765794883524 --- .../SimpleTextInOutSerial/SimpleTextInOut.c | 62 ++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOut.c b/EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOut.c index 583721b39e..85bb08d682 100644 --- a/EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOut.c +++ b/EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOut.c @@ -517,14 +517,72 @@ OutputString ( IN CHAR16 *String ) { - UINTN Size = StrLen(String) + 1; - CHAR8 *OutputString = AllocatePool(Size); + UINTN Size; + CHAR8* OutputString; + EFI_STATUS Status; + EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode; + UINTN MaxColumn; + UINTN MaxRow; + Size = StrLen(String) + 1; + OutputString = AllocatePool(Size); + //If there is any non-ascii characters in String buffer then replace it with '?' //Eventually, UnicodeStrToAsciiStr API should be fixed. SafeUnicodeStrToAsciiStr(String, OutputString); SerialPortWrite ((UINT8 *)OutputString, Size - 1); + // + // Parse each character of the string to output + // to update the cursor position information + // + Mode = This->Mode; + + Status = This->QueryMode ( + This, + Mode->Mode, + &MaxColumn, + &MaxRow + ); + if (EFI_ERROR (Status)) { + return Status; + } + + for (; *String != CHAR_NULL; String++) { + + switch (*String) { + case CHAR_BACKSPACE: + if (Mode->CursorColumn > 0) { + Mode->CursorColumn--; + } + break; + + case CHAR_LINEFEED: + if (Mode->CursorRow < (INT32) (MaxRow - 1)) { + Mode->CursorRow++; + } + break; + + case CHAR_CARRIAGE_RETURN: + Mode->CursorColumn = 0; + break; + + default: + if (Mode->CursorColumn >= (INT32) (MaxColumn - 1)) { + // Move the cursor as if we print CHAR_CARRIAGE_RETURN & CHAR_LINE_FEED + // CHAR_LINEFEED + if (Mode->CursorRow < (INT32) (MaxRow - 1)) { + Mode->CursorRow++; + } + // CHAR_CARIAGE_RETURN + Mode->CursorColumn = 0; + } else { + Mode->CursorColumn++; + } + break; + } + } + FreePool(OutputString); return EFI_SUCCESS; -- 2.39.2