Simplify wincolor_sink::set_foreground_color_
This commit is contained in:
parent
4a5bc41e89
commit
09cc6e7754
@ -130,12 +130,10 @@ std::uint16_t SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_foreground_color_(s
|
|||||||
{
|
{
|
||||||
return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white
|
return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white
|
||||||
}
|
}
|
||||||
|
|
||||||
WORD back_color = orig_buffer_info.wAttributes;
|
// change only the foreground bits (lowest 4 bits)
|
||||||
// retrieve the current background color
|
auto new_attribs = static_cast<WORD>(attribs) | (orig_buffer_info.wAttributes & 0xfff0);
|
||||||
back_color &= static_cast<WORD>(~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY));
|
auto ignored = ::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), new_attribs);
|
||||||
// keep the background color unchanged
|
|
||||||
auto ignored = ::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), static_cast<WORD>(attribs) | back_color);
|
|
||||||
(void)(ignored);
|
(void)(ignored);
|
||||||
return static_cast<std::uint16_t>(orig_buffer_info.wAttributes); // return orig attribs
|
return static_cast<std::uint16_t>(orig_buffer_info.wAttributes); // return orig attribs
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user