mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-27 09:56:31 +00:00
Compare commits
2 Commits
4a5bc41e89
...
42c5eb59c9
Author | SHA1 | Date | |
---|---|---|---|
|
42c5eb59c9 | ||
|
09cc6e7754 |
@ -128,14 +128,13 @@ std::uint16_t SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_foreground_color_(s
|
||||
CONSOLE_SCREEN_BUFFER_INFO orig_buffer_info;
|
||||
if (!::GetConsoleScreenBufferInfo(static_cast<HANDLE>(out_handle_), &orig_buffer_info))
|
||||
{
|
||||
return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white
|
||||
// just return white if failed getting console info
|
||||
return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||
}
|
||||
|
||||
WORD back_color = orig_buffer_info.wAttributes;
|
||||
// retrieve the current background color
|
||||
back_color &= static_cast<WORD>(~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY));
|
||||
// keep the background color unchanged
|
||||
auto ignored = ::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), static_cast<WORD>(attribs) | back_color);
|
||||
|
||||
// change only the foreground bits (lowest 4 bits)
|
||||
auto new_attribs = static_cast<WORD>(attribs) | (orig_buffer_info.wAttributes & 0xfff0);
|
||||
auto ignored = ::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), new_attribs);
|
||||
(void)(ignored);
|
||||
return static_cast<std::uint16_t>(orig_buffer_info.wAttributes); // return orig attribs
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user