feat(wincolor_sink): support print utf-8 string to non-unicode windows console.

pull/2331/head
dhmemi 3 years ago
parent 76fb40d954
commit 7e83620ed1

@ -145,8 +145,14 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::print_range_(const memory_buf_t
{ {
if (end > start) if (end > start)
{ {
auto size = static_cast<DWORD>(end - start); auto size = end - start;
auto ignored = ::WriteConsoleA(static_cast<HANDLE>(out_handle_), formatted.data() + start, size, nullptr, nullptr); #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
wmemory_buf_t buf;
details::os::utf8_to_wstrbuf(string_view_t(formatted.data() + start, size), buf);
auto ignored = ::WriteConsoleW(static_cast<HANDLE>(out_handle_), buf.data(), static_cast<DWORD>(buf.size()), nullptr, nullptr);
#else
auto ignored = ::WriteConsoleA(static_cast<HANDLE>(out_handle_), formatted.data() + start, static_cast<DWORD>(size), nullptr, nullptr);
#endif
(void)(ignored); (void)(ignored);
} }
} }

Loading…
Cancel
Save