From bc78ca42a96a03269d6371a597fb0d47f118d2d6 Mon Sep 17 00:00:00 2001 From: Ryuuke Date: Sun, 8 Feb 2015 23:10:13 +0000 Subject: [PATCH] remove global variables --- format.cc | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/format.cc b/format.cc index d64861aa..c4a00a14 100644 --- a/format.cc +++ b/format.cc @@ -131,8 +131,6 @@ struct IntChecker { FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY }; - WORD RESET_COLOR = 0; - bool reset_color_flag = false; #else const char RESET_COLOR[] = "\x1b[0m"; #endif @@ -1115,19 +1113,16 @@ FMT_FUNC void fmt::print(std::ostream &os, StringRef format_str, ArgList args) { FMT_FUNC void fmt::print_colored(Color c, StringRef format, ArgList args) { #ifdef _WIN32 - HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); - if (handle == INVALID_HANDLE_VALUE) - FMT_THROW(GetLastError(), "cannot get output handle"); - if (!reset_color_flag) { - CONSOLE_SCREEN_BUFFER_INFO infoCon; - if (!GetConsoleScreenBufferInfo(handle, &infoCon)) - FMT_THROW(GetLastError(), "cannot get console informations"); - RESET_COLOR = infoCon.wAttributes; - reset_color_flag = true; - } - WORD color = static_cast(c) >= ARRAYSIZE(win32_colors) ? RESET_COLOR : win32_colors[c]; - if (!SetConsoleTextAttribute(handle, color)) - FMT_THROW(GetLastError(), "cannot set console color"); + HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); + if(handle == INVALID_HANDLE_VALUE) + FMT_THROW(GetLastError(), "cannot get output handle"); + CONSOLE_SCREEN_BUFFER_INFO infoCon; + if(!GetConsoleScreenBufferInfo(handle, &infoCon)) + FMT_THROW(GetLastError(), "cannot get console informations"); + WORD reset_color = infoCon.wAttributes; + WORD color = static_cast(c) >= ARRAYSIZE(win32_colors) ? reset_color : win32_colors[c]; + if(!SetConsoleTextAttribute(handle, color)) + FMT_THROW(GetLastError(), "cannot set console color"); #else char escape[] = "\x1b[30m"; escape[3] = '0' + static_cast(c); @@ -1135,7 +1130,7 @@ FMT_FUNC void fmt::print_colored(Color c, StringRef format, ArgList args) { #endif print(format, args); #ifdef _WIN32 - if(!SetConsoleTextAttribute(handle, RESET_COLOR)) + if(!SetConsoleTextAttribute(handle, reset_color)) FMT_THROW(GetLastError(), "cannot set console color"); #else std::fputs(RESET_COLOR, stdout);