mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 01:29:35 +08:00
Add wide character formatting and output support to wincolor_sink. (#3092)
Fixes printing of unicode characters to the windows console such as microsecond suffix for std::chrono types.
This commit is contained in:
@@ -134,9 +134,18 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::print_range_(const memory_buf_t
|
||||
size_t start,
|
||||
size_t end) {
|
||||
if (end > start) {
|
||||
#if defined(SPDLOG_UTF8_TO_WCHAR_CONSOLE)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user