summaryrefslogtreecommitdiff
path: root/boost/test/utils/setcolor.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/test/utils/setcolor.hpp')
-rw-r--r--boost/test/utils/setcolor.hpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/boost/test/utils/setcolor.hpp b/boost/test/utils/setcolor.hpp
index 91b068ae6f..915c9962a3 100644
--- a/boost/test/utils/setcolor.hpp
+++ b/boost/test/utils/setcolor.hpp
@@ -77,9 +77,11 @@ struct term_color { enum _ {
class setcolor {
public:
// Constructor
- explicit setcolor( term_attr::_ attr = term_attr::NORMAL,
+ explicit setcolor( bool is_color_output = false,
+ term_attr::_ attr = term_attr::NORMAL,
term_color::_ fg = term_color::ORIGINAL,
term_color::_ bg = term_color::ORIGINAL )
+ : m_is_color_output(is_color_output)
{
m_command_size = std::sprintf( m_control_command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40 );
}
@@ -87,7 +89,7 @@ public:
friend std::ostream&
operator<<( std::ostream& os, setcolor const& sc )
{
- if (&os == &std::cout || &os == &std::cerr) {
+ if (sc.m_is_color_output && (&os == &std::cout || &os == &std::cerr)) {
return os.write( sc.m_control_command, sc.m_command_size );
}
return os;
@@ -95,6 +97,7 @@ public:
private:
// Data members
+ bool m_is_color_output;
char m_control_command[13];
int m_command_size;
};
@@ -105,6 +108,9 @@ class setcolor {
protected:
void set_console_color(std::ostream& os, WORD *attributes = NULL) const {
+ if (!m_is_color_output) {
+ return;
+ }
DWORD console_type;
if (&os == &std::cout) {
console_type = STD_OUTPUT_HANDLE;
@@ -127,9 +133,7 @@ protected:
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
GetConsoleScreenBufferInfo(hConsole, &consoleInfo);
- //if(!has_written_console_ext) {
- saved_attributes = consoleInfo.wAttributes;
- //}
+ saved_attributes = consoleInfo.wAttributes;
WORD fg_attr = 0;
switch(m_fg)
@@ -201,20 +205,19 @@ protected:
break;
}
- SetConsoleTextAttribute(hConsole, fg_attr | bg_attr | text_attr);
-
- //has_written_console_ext = true;
+ SetConsoleTextAttribute(hConsole, fg_attr | bg_attr | text_attr);
return;
}
public:
// Constructor
explicit setcolor(
+ bool is_color_output = false,
term_attr::_ attr = term_attr::NORMAL,
term_color::_ fg = term_color::ORIGINAL,
term_color::_ bg = term_color::ORIGINAL )
- : /*has_written_console_ext(false)
- , */m_attr(attr)
+ : m_is_color_output(is_color_output)
+ , m_attr(attr)
, m_fg(fg)
, m_bg(bg)
{}
@@ -227,6 +230,7 @@ public:
}
private:
+ bool m_is_color_output;
term_attr::_ m_attr;
term_color::_ m_fg;
term_color::_ m_bg;
@@ -234,7 +238,6 @@ private:
protected:
// Data members
mutable WORD saved_attributes;
- //mutable bool has_written_console_ext;
};
#endif
@@ -246,24 +249,27 @@ protected:
struct scope_setcolor {
scope_setcolor() : m_os( 0 ) {}
- explicit scope_setcolor( std::ostream& os,
+ explicit scope_setcolor( bool is_color_output,
+ std::ostream& os,
term_attr::_ attr = term_attr::NORMAL,
term_color::_ fg = term_color::ORIGINAL,
term_color::_ bg = term_color::ORIGINAL )
: m_os( &os )
+ , m_is_color_output( is_color_output )
{
- os << setcolor( attr, fg, bg );
+ os << setcolor( is_color_output, attr, fg, bg );
}
~scope_setcolor()
{
if( m_os )
- *m_os << setcolor();
+ *m_os << setcolor( m_is_color_output );
}
private:
scope_setcolor(const scope_setcolor& r);
scope_setcolor& operator=(const scope_setcolor& r);
// Data members
std::ostream* m_os;
+ bool m_is_color_output;
};
#else
@@ -271,13 +277,13 @@ private:
struct scope_setcolor : setcolor {
scope_setcolor() : m_os( 0 ) {}
explicit scope_setcolor(
+ bool is_color_output,
std::ostream& os,
term_attr::_ attr = term_attr::NORMAL,
term_color::_ fg = term_color::ORIGINAL,
term_color::_ bg = term_color::ORIGINAL )
- :
- setcolor(attr, fg, bg),
- m_os( &os )
+ : setcolor(is_color_output, attr, fg, bg)
+ , m_os( &os )
{
os << *this;
}
@@ -298,12 +304,9 @@ private:
#endif
-#define BOOST_TEST_SCOPE_SETCOLOR( is_color_output, os, attr, color ) \
- utils::scope_setcolor const sc( \
- os, \
- is_color_output ? utils::attr : utils::term_attr::NORMAL, \
- is_color_output ? utils::color : utils::term_color::ORIGINAL);\
- ut_detail::ignore_unused_variable_warning( sc ) \
+#define BOOST_TEST_SCOPE_SETCOLOR( is_color_output, os, attr, color ) \
+ utils::scope_setcolor const sc(is_color_output, os, utils::attr, utils::color); \
+ ut_detail::ignore_unused_variable_warning( sc ) \
/**/
} // namespace utils