mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-01-02 10:43:35 +00:00
fix: handle redirected UTF-8 output correctly on Windows (#1147)
This commit is contained in:
parent
ccb6b0ac9d
commit
37c9860b79
@ -95,17 +95,28 @@ static void print_utf8(FILE* stream, const char* utf8) {
|
|||||||
? GetStdHandle(STD_ERROR_HANDLE)
|
? GetStdHandle(STD_ERROR_HANDLE)
|
||||||
: GetStdHandle(STD_OUTPUT_HANDLE);
|
: GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
|
||||||
int wlen = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
|
DWORD mode;
|
||||||
if (wlen <= 0)
|
BOOL is_console = GetConsoleMode(h, &mode);
|
||||||
return;
|
|
||||||
|
|
||||||
wchar_t* wbuf = (wchar_t*)malloc(wlen * sizeof(wchar_t));
|
if (is_console) {
|
||||||
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wbuf, wlen);
|
int wlen = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
|
||||||
|
if (wlen <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
DWORD written;
|
wchar_t* wbuf = (wchar_t*)malloc(wlen * sizeof(wchar_t));
|
||||||
WriteConsoleW(h, wbuf, wlen - 1, &written, NULL);
|
if (!wbuf)
|
||||||
|
return;
|
||||||
|
|
||||||
free(wbuf);
|
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wbuf, wlen);
|
||||||
|
|
||||||
|
DWORD written;
|
||||||
|
WriteConsoleW(h, wbuf, wlen - 1, &written, NULL);
|
||||||
|
|
||||||
|
free(wbuf);
|
||||||
|
} else {
|
||||||
|
DWORD written;
|
||||||
|
WriteFile(h, utf8, (DWORD)strlen(utf8), &written, NULL);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
fputs(utf8, stream);
|
fputs(utf8, stream);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user