Removed public color constants from wincolor sink and intensify red and yellow

This commit is contained in:
Gabi Melman 2021-02-13 20:06:40 +02:00
parent 3e689e700e
commit e931866b35
2 changed files with 19 additions and 28 deletions

View File

@ -17,27 +17,25 @@ namespace spdlog {
namespace sinks {
template<typename ConsoleMutex>
SPDLOG_INLINE wincolor_sink<ConsoleMutex>::wincolor_sink(void *out_handle, color_mode mode)
: BOLD(FOREGROUND_INTENSITY)
, RED(FOREGROUND_RED)
, GREEN(FOREGROUND_GREEN)
, CYAN(FOREGROUND_GREEN | FOREGROUND_BLUE)
, WHITE(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
, YELLOW(FOREGROUND_RED | FOREGROUND_GREEN)
, out_handle_(out_handle)
: out_handle_(out_handle)
, mutex_(ConsoleMutex::mutex())
, formatter_(details::make_unique<spdlog::pattern_formatter>())
{
// check if out_handle is points to the actual console.
// ::GetConsoleMode() should return 0 if it is redirected or not valid console handle.
DWORD console_mode;
in_console_ = ::GetConsoleMode(static_cast<HANDLE>(out_handle_), &console_mode) != 0;
set_color_mode(mode);
colors_[level::trace] = WHITE;
colors_[level::debug] = CYAN;
colors_[level::info] = GREEN;
colors_[level::warn] = YELLOW | BOLD;
colors_[level::err] = RED | BOLD; // red bold
colors_[level::critical] = BACKGROUND_RED | WHITE | BOLD; // white bold on red background
// set level colors
colors_[level::trace] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white
colors_[level::debug] = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan
colors_[level::info] = FOREGROUND_GREEN; // green
colors_[level::warn] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow
colors_[level::err] = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red
colors_[level::critical] =
BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; // intense white on red background
colors_[level::off] = 0;
}
@ -135,7 +133,7 @@ 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 WHITE;
return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white
}
WORD back_color = orig_buffer_info.wAttributes;

View File

@ -24,13 +24,6 @@ template<typename ConsoleMutex>
class wincolor_sink : public sink
{
public:
const std::uint16_t BOLD;
const std::uint16_t RED;
const std::uint16_t GREEN;
const std::uint16_t CYAN;
const std::uint16_t WHITE;
const std::uint16_t YELLOW;
wincolor_sink(void *out_handle, color_mode mode);
~wincolor_sink() override;