diff --git a/GUI/host/textthread.cpp b/GUI/host/textthread.cpp index 7a71b31..0eed0ba 100644 --- a/GUI/host/textthread.cpp +++ b/GUI/host/textthread.cpp @@ -28,6 +28,12 @@ void TextThread::Push(const BYTE* data, int len) { if (len < 0) return; std::scoped_lock lock(bufferMutex); + + BYTE doubleByteChar[2]; + if (len == 1) // doublebyte characters must be processed as pairs + if (leadByte) std::tie(doubleByteChar[0], doubleByteChar[1], data, len, leadByte) = std::tuple(leadByte, data[0], doubleByteChar, 2, 0 ); + else if (IsDBCSLeadByteEx(hp.codepage ? hp.codepage : Host::defaultCodepage, data[0])) std::tie(leadByte, len) = std::tuple(data[0], 0); + if (hp.type & USING_UNICODE) buffer += std::wstring((wchar_t*)data, len / 2); else if (auto converted = Util::StringToWideString(std::string((char*)data, len), hp.codepage ? hp.codepage : Host::defaultCodepage)) buffer += converted.value(); else Host::AddConsoleOutput(INVALID_CODEPAGE); diff --git a/GUI/host/textthread.h b/GUI/host/textthread.h index 9c1979e..c5216fb 100644 --- a/GUI/host/textthread.h +++ b/GUI/host/textthread.h @@ -32,9 +32,10 @@ private: void Flush(); std::wstring buffer; + BYTE leadByte = 0; std::unordered_set repeatingChars; std::mutex bufferMutex; - DWORD lastPushTime; + DWORD lastPushTime = 0; ThreadSafe> queuedSentences; struct TimerDeleter { void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } }; AutoHandle timer = NULL; // this needs to be last so it's destructed first