20 #include <unordered_map> 29 template<
typename OutHandle,
typename ConsoleMutex>
36 const WORD CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE;
37 const WORD WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
64 std::lock_guard<mutex_t> lock(
mutex_);
70 std::lock_guard<mutex_t> lock(
mutex_);
73 if (
msg.color_range_end >
msg.color_range_start)
99 std::lock_guard<mutex_t> lock(
mutex_);
103 void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
override final 105 std::lock_guard<mutex_t> lock(
mutex_);
110 using mutex_t =
typename ConsoleMutex::mutex_t;
114 CONSOLE_SCREEN_BUFFER_INFO orig_buffer_info;
115 ::GetConsoleScreenBufferInfo(
out_handle_, &orig_buffer_info);
116 WORD back_color = orig_buffer_info.wAttributes;
118 back_color &=
static_cast<WORD>(~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY));
120 ::SetConsoleTextAttribute(
out_handle_, attribs | back_color);
121 return orig_buffer_info.wAttributes;
127 auto size =
static_cast<DWORD
>(end - start);
128 ::WriteConsoleA(
out_handle_, formatted.data() + start,
size,
nullptr,
nullptr);
133 std::unordered_map<level::level_enum, WORD, level::level_hasher>
colors_;
wincolor_sink & operator=(const wincolor_sink &other)=delete
void msg(const char *fmt,...)
typename ConsoleMutex::mutex_t mutex_t
void flush() final override
std::unique_ptr< spdlog::formatter > formatter_
~wincolor_sink() override
void log(const details::log_msg &msg) final override
void set_pattern(const std::string &pattern) override final
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
std::unordered_map< level::level_enum, WORD, level::level_hasher > colors_
level::level_enum level() const
void set_formatter(std::unique_ptr< spdlog::formatter > sink_formatter) override final
void print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end)
void set_color(level::level_enum level, WORD color)
WORD set_console_attribs(WORD attribs)