Commit 43fe1008 authored by Victor Zverovich's avatar Victor Zverovich

Move the implementation of ColorWriter::operator() to format.cc

parent 6968ef3b
...@@ -82,6 +82,8 @@ inline int FMT_SNPRINTF(char *buffer, size_t size, const char *format, ...) { ...@@ -82,6 +82,8 @@ inline int FMT_SNPRINTF(char *buffer, size_t size, const char *format, ...) {
} }
#endif // _MSC_VER #endif // _MSC_VER
const char RESET_COLOR[] = "\x1b[0m";
} }
template <typename T> template <typename T>
...@@ -663,7 +665,13 @@ void fmt::BasicFormatter<Char>::DoFormat() { ...@@ -663,7 +665,13 @@ void fmt::BasicFormatter<Char>::DoFormat() {
writer.buffer_.append(start, s); writer.buffer_.append(start, s);
} }
const char fmt::ColorWriter::RESET[] = "\x1b[0m"; void fmt::ColorWriter::operator()(const fmt::BasicWriter<char> &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. // Explicit instantiations for char.
......
...@@ -1472,19 +1472,12 @@ enum Color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE}; ...@@ -1472,19 +1472,12 @@ enum Color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
class ColorWriter { class ColorWriter {
private: private:
Color color_; Color color_;
static const char RESET[];
public: public:
explicit ColorWriter(Color c) : color_(c) {} explicit ColorWriter(Color c) : color_(c) {}
/** Writes the colored output to stdout. */ /** Writes the colored output to stdout. */
void operator()(const BasicWriter<char> &w) const { void operator()(const BasicWriter<char> &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);
}
}; };
// Formats a string and prints it to stdout with the given color. // Formats a string and prints it to stdout with the given color.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment