From: José Fonseca Date: Tue, 23 Nov 2010 11:42:06 +0000 (+0000) Subject: Fix windows formatting. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=3ade2112c3a0e8a3227eea2640ede1c722bd3a15;p=apitrace Fix windows formatting. --- diff --git a/formatter.hpp b/formatter.hpp index c1568a6..c2d3455 100644 --- a/formatter.hpp +++ b/formatter.hpp @@ -40,7 +40,7 @@ class Attribute { public: virtual ~Attribute() {} - virtual std::ostream& apply(std::ostream& os) const { return os; } + virtual void apply(std::ostream& os) const {} }; @@ -67,8 +67,8 @@ protected: const char *escape; public: AnsiAttribute(const char *_escape) : escape(_escape) {} - std::ostream & apply(std::ostream& os) const { - return os << "\33[" << escape; + void apply(std::ostream& os) const { + os << "\33[" << escape; } }; @@ -96,7 +96,8 @@ public: inline std::ostream& operator<<(std::ostream& os, const Attribute *attr) { - return attr->apply(os); + attr->apply(os); + return os; } @@ -109,17 +110,20 @@ protected: WORD wAttributes; public: WindowsAttribute(WORD _wAttributes) : wAttributes(_wAttributes) {} - std::ostream & apply(std::ostream& os) const { + void apply(std::ostream& os) const { DWORD nStdHandleOutput; if (os == std::cout) { nStdHandleOutput = STD_OUTPUT_HANDLE; } else if (os == std::cerr) { nStdHandleOutput = STD_ERROR_HANDLE; } else { - return os; + return; } - HANDLE hConsoleOutput = GetStdHandle(nStdHandleOutput); + if (hConsoleOutput == INVALID_HANDLE_VALUE) { + return; + } + SetConsoleTextAttribute(hConsoleOutput, wAttributes); } };