X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fformatter.hpp;h=75a407f7469ee421f3cde1c9bc8b7e4a68a4772d;hb=a7e7b27a13dc40db4ec96bc1bba667644ef0a896;hp=181e2d1539d5c14bc14e070db1325a31d2593ad4;hpb=ae2b4d32ed56e3ac193cc7205aeb58082c448ce8;p=apitrace diff --git a/common/formatter.hpp b/common/formatter.hpp index 181e2d1..75a407f 100644 --- a/common/formatter.hpp +++ b/common/formatter.hpp @@ -33,8 +33,41 @@ #include +#ifdef _WIN32 +#include + +#ifndef COMMON_LVB_LEADING_BYTE +#define COMMON_LVB_LEADING_BYTE 0x0100 +#endif + +#ifndef COMMON_LVB_TRAILING_BYTE +#define COMMON_LVB_TRAILING_BYTE 0x0200 +#endif + +#ifndef COMMON_LVB_GRID_HORIZONTAL +#define COMMON_LVB_GRID_HORIZONTAL 0x0400 +#endif + +#ifndef COMMON_LVB_GRID_LVERTICAL +#define COMMON_LVB_GRID_LVERTICAL 0x0800 +#endif + +#ifndef COMMON_LVB_GRID_RVERTICAL +#define COMMON_LVB_GRID_RVERTICAL 0x1000 +#endif -namespace Formatter { +#ifndef COMMON_LVB_REVERSE_VIDEO +#define COMMON_LVB_REVERSE_VIDEO 0x4000 +#endif + +#ifndef COMMON_LVB_UNDERSCORE +#define COMMON_LVB_UNDERSCORE 0x8000 +#endif + +#endif /* _WIN32 */ + + +namespace formatter { /* * See also http://bytes.com/topic/c/answers/63822-design-question-little-c-header-colorizing-text-linux-comments-ideas @@ -62,6 +95,7 @@ public: virtual Attribute *normal(void) const { return new Attribute; } virtual Attribute *bold(void) const { return new Attribute; } virtual Attribute *italic(void) const { return new Attribute; } + virtual Attribute *strike(void) const { return new Attribute; } virtual Attribute *color(Color) const { return new Attribute; } }; @@ -87,7 +121,11 @@ protected: public: virtual Attribute *normal(void) const { return new AnsiAttribute("0m"); } virtual Attribute *bold(void) const { return new AnsiAttribute("1m"); } + /* Italic is not widely supported, or worse, implemented with a reverse */ +#if 0 virtual Attribute *italic(void) const { return new AnsiAttribute("3m"); } +#endif + virtual Attribute *strike(void) const { return new AnsiAttribute("9m"); } virtual Attribute *color(Color c) const { static const char *color_escapes[] = { "31m", /* red */ @@ -107,7 +145,6 @@ inline std::ostream& operator<<(std::ostream& os, const Attribute *attr) { #ifdef _WIN32 -#include class WindowsAttribute : public Attribute { protected: @@ -142,6 +179,7 @@ public: virtual Attribute *normal(void) const { return new WindowsAttribute(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); } virtual Attribute *bold(void) const { return new WindowsAttribute(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); } virtual Attribute *italic(void) const { return new WindowsAttribute(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); } + virtual Attribute *strike(void) const { return new WindowsAttribute(COMMON_LVB_REVERSE_VIDEO | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); } virtual Attribute *color(Color c) const { static const WORD color_escapes[] = { FOREGROUND_RED | FOREGROUND_INTENSITY, @@ -152,12 +190,25 @@ public: } }; -#endif + +#endif /* _WIN32 */ inline Formatter *defaultFormatter(bool color = true) { if (color) { #ifdef _WIN32 + // http://wiki.winehq.org/DeveloperFaq#detect-wine + static HMODULE hNtDll = NULL; + static bool bWine = false; + if (!hNtDll) { + hNtDll = LoadLibraryA("ntdll"); + if (hNtDll) { + bWine = GetProcAddress(hNtDll, "wine_get_version") != NULL; + } + } + if (bWine) { + return new AnsiFormatter; + } return new WindowsFormatter; #else return new AnsiFormatter; @@ -168,7 +219,7 @@ inline Formatter *defaultFormatter(bool color = true) { } -} /* namespace Formatter */ +} /* namespace formatter */ #endif /* _FORMATTER_HPP_ */