|
|
|
@ -37,10 +37,11 @@ public:
|
|
|
|
|
const WORD WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
|
|
|
|
const WORD YELLOW = FOREGROUND_RED | FOREGROUND_GREEN;
|
|
|
|
|
|
|
|
|
|
wincolor_sink()
|
|
|
|
|
wincolor_sink(color_mode mode = color_mode::automatic)
|
|
|
|
|
: out_handle_(OutHandle::handle())
|
|
|
|
|
, mutex_(ConsoleMutex::mutex())
|
|
|
|
|
{
|
|
|
|
|
set_color_mode(mode);
|
|
|
|
|
colors_[level::trace] = WHITE;
|
|
|
|
|
colors_[level::debug] = CYAN;
|
|
|
|
|
colors_[level::info] = GREEN;
|
|
|
|
@ -70,7 +71,7 @@ public:
|
|
|
|
|
std::lock_guard<mutex_t> lock(mutex_);
|
|
|
|
|
fmt::memory_buffer formatted;
|
|
|
|
|
formatter_->format(msg, formatted);
|
|
|
|
|
if (msg.color_range_end > msg.color_range_start)
|
|
|
|
|
if (should_do_colors_ && msg.color_range_end > msg.color_range_start)
|
|
|
|
|
{
|
|
|
|
|
// before color range
|
|
|
|
|
print_range_(formatted, 0, msg.color_range_start);
|
|
|
|
@ -83,7 +84,7 @@ public:
|
|
|
|
|
// after color range
|
|
|
|
|
print_range_(formatted, msg.color_range_end, formatted.size());
|
|
|
|
|
}
|
|
|
|
|
else // print without colors if color range is invalid
|
|
|
|
|
else // print without colors if color range is invalid (or color is disabled)
|
|
|
|
|
{
|
|
|
|
|
print_range_(formatted, 0, formatted.size());
|
|
|
|
|
}
|
|
|
|
@ -106,6 +107,20 @@ public:
|
|
|
|
|
formatter_ = std::move(sink_formatter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_color_mode(color_mode mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode)
|
|
|
|
|
{
|
|
|
|
|
case color_mode::always:
|
|
|
|
|
case color_mode::automatic:
|
|
|
|
|
should_do_colors_ = true;
|
|
|
|
|
return;
|
|
|
|
|
case color_mode::never:
|
|
|
|
|
should_do_colors_ = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
using mutex_t = typename ConsoleMutex::mutex_t;
|
|
|
|
|
// set color and return the orig console attributes (for resetting later)
|
|
|
|
@ -130,6 +145,7 @@ private:
|
|
|
|
|
|
|
|
|
|
HANDLE out_handle_;
|
|
|
|
|
mutex_t &mutex_;
|
|
|
|
|
bool should_do_colors_;
|
|
|
|
|
std::unordered_map<level::level_enum, WORD, level::level_hasher> colors_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|