mirror of
https://github.com/fmtlib/fmt.git
synced 2025-08-05 05:34:44 +02:00
Update the contributed code to the used coding conventions
This commit is contained in:
45
format.cc
45
format.cc
@@ -120,19 +120,18 @@ struct IntChecker<true> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
uint8_t win32_colors[] =
|
const uint8_t WIN32_COLORS[] = {
|
||||||
{
|
0,
|
||||||
0,
|
FOREGROUND_RED | FOREGROUND_INTENSITY,
|
||||||
FOREGROUND_RED | FOREGROUND_INTENSITY,
|
FOREGROUND_GREEN | FOREGROUND_INTENSITY,
|
||||||
FOREGROUND_GREEN | FOREGROUND_INTENSITY,
|
FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY,
|
||||||
FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY,
|
FOREGROUND_BLUE | FOREGROUND_INTENSITY,
|
||||||
FOREGROUND_BLUE | FOREGROUND_INTENSITY,
|
FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY,
|
||||||
FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY,
|
FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
|
||||||
FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE,
|
FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY
|
||||||
FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY
|
};
|
||||||
};
|
|
||||||
#else
|
#else
|
||||||
const char RESET_COLOR[] = "\x1b[0m";
|
const char RESET_COLOR[] = "\x1b[0m";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void (*FormatFunc)(fmt::Writer &, int, fmt::StringRef);
|
typedef void (*FormatFunc)(fmt::Writer &, int, fmt::StringRef);
|
||||||
@@ -1114,25 +1113,23 @@ 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) {
|
FMT_FUNC void fmt::print_colored(Color c, StringRef format, ArgList args) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
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");
|
||||||
CONSOLE_SCREEN_BUFFER_INFO infoCon;
|
CONSOLE_SCREEN_BUFFER_INFO info_con;
|
||||||
if(!GetConsoleScreenBufferInfo(handle, &infoCon))
|
if (!GetConsoleScreenBufferInfo(handle, &info_con))
|
||||||
FMT_THROW(GetLastError(), "cannot get console informations");
|
FMT_THROW(GetLastError(), "cannot get console information");
|
||||||
WORD reset_color = infoCon.wAttributes;
|
WORD reset_color = info_con.wAttributes;
|
||||||
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");
|
||||||
|
print(format, args);
|
||||||
|
if (!SetConsoleTextAttribute(handle, reset_color))
|
||||||
FMT_THROW(GetLastError(), "cannot set console color");
|
FMT_THROW(GetLastError(), "cannot set console color");
|
||||||
#else
|
#else
|
||||||
char escape[] = "\x1b[30m";
|
char escape[] = "\x1b[30m";
|
||||||
escape[3] = '0' + static_cast<char>(c);
|
escape[3] = '0' + static_cast<char>(c);
|
||||||
std::fputs(escape, stdout);
|
std::fputs(escape, stdout);
|
||||||
#endif
|
|
||||||
print(format, args);
|
print(format, args);
|
||||||
#ifdef _WIN32
|
|
||||||
if(!SetConsoleTextAttribute(handle, reset_color))
|
|
||||||
FMT_THROW(GetLastError(), "cannot set console color");
|
|
||||||
#else
|
|
||||||
std::fputs(RESET_COLOR, stdout);
|
std::fputs(RESET_COLOR, stdout);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user