Skip to content

Commit

Permalink
Fix redefinition warning for RESET_COLOR
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvCW authored and vitaut committed Jul 4, 2018
1 parent c04fb91 commit ec218a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 7 additions & 9 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ inline int fmt_snprintf(char *buffer, size_t size, const char *format, ...) {
# define FMT_SWPRINTF swprintf
#endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT)

const char RESET_COLOR[] = "\x1b[0m";
const wchar_t WRESET_COLOR[] = L"\x1b[0m";

typedef void (*FormatFunc)(internal::buffer &, int, string_view);

// Portable thread-safe version of strerror.
Expand Down Expand Up @@ -312,6 +309,9 @@ const int16_t basic_data<T>::POW10_EXPONENTS[] = {
827, 853, 880, 907, 933, 960, 986, 1013, 1039, 1066
};

template <typename T> const char basic_data<T>::RESET_COLOR[] = "\x1b[0m";
template <typename T> const wchar_t basic_data<T>::WRESET_COLOR[] = L"\x1b[0m";

FMT_FUNC fp operator*(fp x, fp y) {
// Multiply 32-bit parts of significands.
uint64_t mask = (1ULL << 32) - 1;
Expand Down Expand Up @@ -505,15 +505,15 @@ FMT_FUNC void vprint_colored(color c, string_view format, format_args args) {
escape[3] = static_cast<char>('0' + c);
std::fputs(escape, stdout);
vprint(format, args);
std::fputs(RESET_COLOR, stdout);
std::fputs(internal::data::RESET_COLOR, stdout);
}

FMT_FUNC void vprint_colored(color c, wstring_view format, wformat_args args) {
wchar_t escape[] = L"\x1b[30m";
escape[3] = static_cast<wchar_t>('0' + c);
std::fputws(escape, stdout);
vprint(format, args);
std::fputws(WRESET_COLOR, stdout);
std::fputws(internal::data::WRESET_COLOR, stdout);
}
#else
namespace internal {
Expand All @@ -526,20 +526,18 @@ FMT_CONSTEXPR void to_esc(uint8_t c, char out[], int offset) {

FMT_FUNC void vprint_rgb(rgb fd, string_view format, format_args args) {
char escape_fd[] = "\x1b[38;2;000;000;000m";
static FMT_CONSTEXPR_DECL const char RESET_COLOR[] = "\x1b[0m";
internal::to_esc(fd.r, escape_fd, 7);
internal::to_esc(fd.g, escape_fd, 11);
internal::to_esc(fd.b, escape_fd, 15);

std::fputs(escape_fd, stdout);
vprint(format, args);
std::fputs(RESET_COLOR, stdout);
std::fputs(internal::data::RESET_COLOR, stdout);
}

FMT_FUNC void vprint_rgb(rgb fd, rgb bg, string_view format, format_args args) {
char escape_fd[] = "\x1b[38;2;000;000;000m"; // foreground color
char escape_bg[] = "\x1b[48;2;000;000;000m"; // background color
static FMT_CONSTEXPR_DECL const char RESET_COLOR[] = "\x1b[0m";
internal::to_esc(fd.r, escape_fd, 7);
internal::to_esc(fd.g, escape_fd, 11);
internal::to_esc(fd.b, escape_fd, 15);
Expand All @@ -551,7 +549,7 @@ FMT_FUNC void vprint_rgb(rgb fd, rgb bg, string_view format, format_args args) {
std::fputs(escape_fd, stdout);
std::fputs(escape_bg, stdout);
vprint(format, args);
std::fputs(RESET_COLOR, stdout);
std::fputs(internal::data::RESET_COLOR, stdout);
}
#endif

Expand Down
2 changes: 2 additions & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,8 @@ struct FMT_API basic_data {
static const uint64_t POW10_SIGNIFICANDS[];
static const int16_t POW10_EXPONENTS[];
static const char DIGITS[];
static const char RESET_COLOR[];
static const wchar_t WRESET_COLOR[];
};

#if FMT_USE_EXTERN_TEMPLATES
Expand Down

0 comments on commit ec218a3

Please sign in to comment.