Add wide character formatting and output support to wincolor_sink.

Fixes printing of unicode characters to the windows console such as microsecond suffix for std::chrono types.
pull/3010/head
Dominik Grabiec 2 years ago
parent 696db97f67
commit 904e56702e

@ -134,19 +134,36 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::print_range_(const memory_buf_t
size_t start,
size_t end) {
if (end > start) {
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
wmemory_buf_t wformatted;
details::os::utf8_to_wstrbuf(string_view_t(formatted.data() + start, end - start),
wformatted);
auto size = static_cast<DWORD>(wformatted.size());
auto ignored = ::WriteConsoleW(static_cast<HANDLE>(out_handle_), wformatted.data(), size,
nullptr, nullptr);
#else
auto size = static_cast<DWORD>(end - start);
auto ignored = ::WriteConsoleA(static_cast<HANDLE>(out_handle_), formatted.data() + start,
size, nullptr, nullptr);
#endif
(void)(ignored);
}
}
template <typename ConsoleMutex>
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_t &formatted) {
auto size = static_cast<DWORD>(formatted.size());
DWORD bytes_written = 0;
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
wmemory_buf_t wformatted;
details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), wformatted);
auto size = static_cast<DWORD>(wformatted.size() * sizeof(WCHAR));
auto ignored = ::WriteFile(static_cast<HANDLE>(out_handle_), wformatted.data(), size,
&bytes_written, nullptr);
#else
auto size = static_cast<DWORD>(formatted.size());
auto ignored = ::WriteFile(static_cast<HANDLE>(out_handle_), formatted.data(), size,
&bytes_written, nullptr);
#endif
(void)(ignored);
}

Loading…
Cancel
Save