mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-26 00:21:13 +00:00
remove global variables
This commit is contained in:
parent
4806f75469
commit
bc78ca42a9
11
format.cc
11
format.cc
@ -131,8 +131,6 @@ struct IntChecker<true> {
|
|||||||
FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE,
|
FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE,
|
||||||
FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY
|
FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY
|
||||||
};
|
};
|
||||||
WORD RESET_COLOR = 0;
|
|
||||||
bool reset_color_flag = false;
|
|
||||||
#else
|
#else
|
||||||
const char RESET_COLOR[] = "\x1b[0m";
|
const char RESET_COLOR[] = "\x1b[0m";
|
||||||
#endif
|
#endif
|
||||||
@ -1118,14 +1116,11 @@ FMT_FUNC void fmt::print_colored(Color c, StringRef format, ArgList args) {
|
|||||||
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
if(handle == INVALID_HANDLE_VALUE)
|
if(handle == INVALID_HANDLE_VALUE)
|
||||||
FMT_THROW(GetLastError(), "cannot get output handle");
|
FMT_THROW(GetLastError(), "cannot get output handle");
|
||||||
if (!reset_color_flag) {
|
|
||||||
CONSOLE_SCREEN_BUFFER_INFO infoCon;
|
CONSOLE_SCREEN_BUFFER_INFO infoCon;
|
||||||
if(!GetConsoleScreenBufferInfo(handle, &infoCon))
|
if(!GetConsoleScreenBufferInfo(handle, &infoCon))
|
||||||
FMT_THROW(GetLastError(), "cannot get console informations");
|
FMT_THROW(GetLastError(), "cannot get console informations");
|
||||||
RESET_COLOR = infoCon.wAttributes;
|
WORD reset_color = infoCon.wAttributes;
|
||||||
reset_color_flag = true;
|
WORD color = static_cast<int>(c) >= ARRAYSIZE(win32_colors) ? reset_color : win32_colors[c];
|
||||||
}
|
|
||||||
WORD color = static_cast<int>(c) >= ARRAYSIZE(win32_colors) ? RESET_COLOR : win32_colors[c];
|
|
||||||
if(!SetConsoleTextAttribute(handle, color))
|
if(!SetConsoleTextAttribute(handle, color))
|
||||||
FMT_THROW(GetLastError(), "cannot set console color");
|
FMT_THROW(GetLastError(), "cannot set console color");
|
||||||
#else
|
#else
|
||||||
@ -1135,7 +1130,7 @@ FMT_FUNC void fmt::print_colored(Color c, StringRef format, ArgList args) {
|
|||||||
#endif
|
#endif
|
||||||
print(format, args);
|
print(format, args);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if(!SetConsoleTextAttribute(handle, RESET_COLOR))
|
if(!SetConsoleTextAttribute(handle, reset_color))
|
||||||
FMT_THROW(GetLastError(), "cannot set console color");
|
FMT_THROW(GetLastError(), "cannot set console color");
|
||||||
#else
|
#else
|
||||||
std::fputs(RESET_COLOR, stdout);
|
std::fputs(RESET_COLOR, stdout);
|
||||||
|
Loading…
Reference in New Issue
Block a user