diff --git a/contrib/win32/win32compat/console.c b/contrib/win32/win32compat/console.c index 03d9e4a..ad0c435 100644 --- a/contrib/win32/win32compat/console.c +++ b/contrib/win32/win32compat/console.c @@ -315,6 +315,9 @@ void ConSetAttribute(int *iParam, int iParamCount) case ANSI_ATTR_RESET: iAttr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; + iAttr = iAttr & ~BACKGROUND_RED; + iAttr = iAttr & ~BACKGROUND_BLUE; + iAttr = iAttr & ~BACKGROUND_GREEN; iAttr = iAttr & ~BACKGROUND_INTENSITY; iAttr = iAttr & ~FOREGROUND_INTENSITY; iAttr = iAttr & ~COMMON_LVB_UNDERSCORE; @@ -530,12 +533,24 @@ void ConFillToEndOfLine() int ConWriteString(char* pszString, int cbString) { DWORD Result = 0; + int needed = 0; + int cnt = 0; + wchar_t* utf16 = NULL; + + if ((needed = MultiByteToWideChar(CP_UTF8, 0, pszString, cbString, NULL, 0)) == 0 || + (utf16 = malloc(needed * sizeof(wchar_t))) == NULL || + (cnt = MultiByteToWideChar(CP_UTF8, 0, pszString, cbString, utf16, needed)) == 0) { + Result = (DWORD)printf(pszString); + } else { + if (hOutputConsole) + WriteConsoleW(hOutputConsole, utf16, cnt, &Result, 0); + else + Result = (DWORD)wprintf(utf16); + } + + if(utf16) + free(utf16); - if (hOutputConsole) - WriteConsole(hOutputConsole, pszString, cbString, &Result, 0); - else - Result = (DWORD) printf(pszString); - return cbString; } diff --git a/contrib/win32/win32compat/shell-host.c b/contrib/win32/win32compat/shell-host.c index ae7cd4f..1684592 100644 --- a/contrib/win32/win32compat/shell-host.c +++ b/contrib/win32/win32compat/shell-host.c @@ -250,7 +250,7 @@ void SendHorizontalScroll(HANDLE hInput, int cells) { WriteFile(hInput, formatted_output, out, &wr, NULL); } -void SendCharacter(HANDLE hInput, WORD attributes, char character) { +void SendCharacter(HANDLE hInput, WORD attributes, wchar_t character) { DWORD wr = 0; DWORD out = 0; @@ -266,6 +266,9 @@ void SendCharacter(HANDLE hInput, WORD attributes, char character) { PSTR Next; size_t SizeLeft; + if (!character) + return; + Next = formatted_output; SizeLeft = sizeof formatted_output; @@ -339,52 +342,33 @@ void SendCharacter(HANDLE hInput, WORD attributes, char character) { if (bUseAnsiEmulation && attributes != pattributes) WriteFile(hInput, formatted_output, (Next - formatted_output), &wr, NULL); - WriteFile(hInput, &character, 1, &wr, NULL); + // East asian languages have 2 bytes for each character, only use the first + if (!(attributes & COMMON_LVB_TRAILING_BYTE)) + { + int nSize = WideCharToMultiByte(CP_UTF8, + 0, + &character, + 1, + Next, + 10, + NULL, + NULL); + + if(nSize > 0) + WriteFile(hInput, Next, nSize, &wr, NULL); + } pattributes = attributes; } void SendBuffer(HANDLE hInput, CHAR_INFO *buffer, DWORD bufferSize) { - - DWORD wr = 0; - DWORD out = 0; - DWORD current = 0; - - char* formatted_output = NULL; - - USHORT Color = 0; - ULONG Status = 0; if (bufferSize <= 0) return; - formatted_output = (char *)malloc(bufferSize); - - PSTR Next; - Next = formatted_output; - for (DWORD i = 0; i < bufferSize; i++) { - // East asian languages have 2 bytes for each character, only use the first - if (!(buffer[i].Attributes & COMMON_LVB_TRAILING_BYTE)) - { - WideCharToMultiByte(cp, - 0, - &buffer[i].Char.UnicodeChar, - 1, - Next, - 1, - NULL, - NULL); - - SendCharacter(hInput, buffer[i].Attributes, *Next); - - Next++; - } - } - - if (formatted_output) { - free(formatted_output); + SendCharacter(hInput, buffer[i].Attributes, buffer[i].Char.UnicodeChar); } } @@ -465,7 +449,8 @@ DWORD WINAPI MonitorChild(_In_ LPVOID lpParameter) { DWORD ProcessEvent(void *p) { char f[255]; - char chUpdate; + wchar_t chUpdate; + WORD wAttributes; WORD wX; WORD wY; diff --git a/contrib/win32/win32compat/tncon.c b/contrib/win32/win32compat/tncon.c index db1af7b..c06fc4d 100644 --- a/contrib/win32/win32compat/tncon.c +++ b/contrib/win32/win32compat/tncon.c @@ -166,7 +166,7 @@ int ReadConsoleForTermEmul(HANDLE hInput, char *destin, int destinlen) if (InputRecord.Event.KeyEvent.bKeyDown) { int n = WideCharToMultiByte( - GetConsoleCP(), + CP_UTF8, 0, &(InputRecord.Event.KeyEvent.uChar.UnicodeChar), 1,