From 062cd07342edc2b003555e90dd2cee0514b9f64a Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:55 +0100 Subject: Add BanditCpp 1.1.4 test harness --- vendor/bandit/bandit/reporters/colorizer.h | 99 ++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 vendor/bandit/bandit/reporters/colorizer.h (limited to 'vendor/bandit/bandit/reporters/colorizer.h') diff --git a/vendor/bandit/bandit/reporters/colorizer.h b/vendor/bandit/bandit/reporters/colorizer.h new file mode 100644 index 00000000..217bdddf --- /dev/null +++ b/vendor/bandit/bandit/reporters/colorizer.h @@ -0,0 +1,99 @@ +#ifndef BANDIT_REPORTERS_COLORIZER_H +#define BANDIT_REPORTERS_COLORIZER_H + +#ifdef _WIN32 + #ifndef MINGW32 + #define NOMINMAX + #endif + + #define WIN32_LEAN_AND_MEAN + #include +#endif + +namespace bandit { namespace detail { + +#ifdef _WIN32 + struct colorizer + { + colorizer(bool colors_enabled = true) + : colors_enabled_(colors_enabled), + stdout_handle_(GetStdHandle(STD_OUTPUT_HANDLE)) + { + original_color_ = get_console_color(); + } + + const char* green() const + { + if(colors_enabled_) + { + set_console_color(FOREGROUND_GREEN); + } + return ""; + } + + const char* red() const + { + if(colors_enabled_) + { + set_console_color(FOREGROUND_RED); + } + return ""; + } + + const char* reset() const + { + if(colors_enabled_) + { + set_console_color(original_color_); + } + return ""; + } + + private: + WORD get_console_color() const + { + CONSOLE_SCREEN_BUFFER_INFO info = {0}; + GetConsoleScreenBufferInfo(stdout_handle_, &info); + return info.wAttributes; + } + + void set_console_color(WORD color) const + { + SetConsoleTextAttribute(stdout_handle_, color); + } + + private: + bool colors_enabled_; + HANDLE stdout_handle_; + WORD original_color_; + }; + +#else + struct colorizer + { + colorizer(bool colors_enabled = true) + : colors_enabled_(colors_enabled) + {} + + const char* green() const + { + return colors_enabled_ ? "\033[1;32m" : ""; + } + + const char* red() const + { + return colors_enabled_ ? "\033[1;31m" : ""; + } + + const char* reset() const + { + return colors_enabled_ ? "\033[0m" : ""; + } + + private: + bool colors_enabled_; + }; +#endif +}} + +#endif -- cgit v1.2.3 From 7b9f4e4e8169ca2fad3a1c7ca03f07ecfc46678e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 1 Aug 2015 16:35:25 +0200 Subject: Bandit 2.0.0 --- vendor/bandit/bandit/reporters/colorizer.h | 46 ++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'vendor/bandit/bandit/reporters/colorizer.h') diff --git a/vendor/bandit/bandit/reporters/colorizer.h b/vendor/bandit/bandit/reporters/colorizer.h index 217bdddf..e8979eec 100644 --- a/vendor/bandit/bandit/reporters/colorizer.h +++ b/vendor/bandit/bandit/reporters/colorizer.h @@ -2,7 +2,7 @@ #define BANDIT_REPORTERS_COLORIZER_H #ifdef _WIN32 - #ifndef MINGW32 + #ifndef NOMINMAX #define NOMINMAX #endif @@ -31,6 +31,24 @@ namespace bandit { namespace detail { return ""; } + const char* yellow() const + { + if(colors_enabled_) + { + set_console_color(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); + } + return ""; + } + + const char* blue() const + { + if(colors_enabled_) + { + set_console_color(FOREGROUND_BLUE); + } + return ""; + } + const char* red() const { if(colors_enabled_) @@ -40,6 +58,15 @@ namespace bandit { namespace detail { return ""; } + const char* white() const + { + if(colors_enabled_) + { + set_console_color(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); + } + return ""; + } + const char* reset() const { if(colors_enabled_) @@ -52,7 +79,7 @@ namespace bandit { namespace detail { private: WORD get_console_color() const { - CONSOLE_SCREEN_BUFFER_INFO info = {0}; + CONSOLE_SCREEN_BUFFER_INFO info{}; GetConsoleScreenBufferInfo(stdout_handle_, &info); return info.wAttributes; } @@ -80,11 +107,26 @@ namespace bandit { namespace detail { return colors_enabled_ ? "\033[1;32m" : ""; } + const char* yellow() const + { + return colors_enabled_ ? "\033[1;33m" : ""; + } + + const char* blue() const + { + return colors_enabled_ ? "\033[1;34m" : ""; + } + const char* red() const { return colors_enabled_ ? "\033[1;31m" : ""; } + const char* white() const + { + return colors_enabled_ ? "\033[1;37m" : ""; + } + const char* reset() const { return colors_enabled_ ? "\033[0m" : ""; -- cgit v1.2.3