diff --git a/format.cc b/format.cc index f191e3a4..8bb7c6bf 100644 --- a/format.cc +++ b/format.cc @@ -82,6 +82,8 @@ inline int FMT_SNPRINTF(char *buffer, size_t size, const char *format, ...) { } #endif // _MSC_VER + +const char RESET_COLOR[] = "\x1b[0m"; } template @@ -663,7 +665,13 @@ void fmt::BasicFormatter::DoFormat() { writer.buffer_.append(start, s); } -const char fmt::ColorWriter::RESET[] = "\x1b[0m"; +void fmt::ColorWriter::operator()(const fmt::BasicWriter &w) const { + char escape[] = "\x1b[30m"; + escape[3] = '0' + color_; + std::fputs(escape, stdout); + std::fwrite(w.data(), 1, w.size(), stdout); + std::fputs(RESET_COLOR, stdout); +} // Explicit instantiations for char. diff --git a/format.h b/format.h index eaf9f5c0..9c5495ca 100644 --- a/format.h +++ b/format.h @@ -1472,19 +1472,12 @@ enum Color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE}; class ColorWriter { private: Color color_; - static const char RESET[]; public: explicit ColorWriter(Color c) : color_(c) {} /** Writes the colored output to stdout. */ - void operator()(const BasicWriter &w) const { - char escape[] = "\x1b[30m"; - escape[3] = '0' + color_; - std::fputs(escape, stdout); - std::fwrite(w.data(), 1, w.size(), stdout); - std::fputs(RESET, stdout); - } + void operator()(const BasicWriter &w) const; }; // Formats a string and prints it to stdout with the given color.