1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : contains definition for setcolor iostream manipulator
13 // ***************************************************************************
15 #ifndef BOOST_TEST_UTILS_SETCOLOR_HPP
16 #define BOOST_TEST_UTILS_SETCOLOR_HPP
19 #include <boost/test/detail/config.hpp>
25 #include <boost/test/detail/suppress_warnings.hpp>
27 //____________________________________________________________________________//
33 // ************************************************************************** //
34 // ************** term_attr ************** //
35 // ************************************************************************** //
37 struct term_attr { enum _ {
47 // ************************************************************************** //
48 // ************** term_color ************** //
49 // ************************************************************************** //
51 struct term_color { enum _ {
63 // ************************************************************************** //
64 // ************** setcolor ************** //
65 // ************************************************************************** //
70 explicit setcolor( term_attr::_ attr = term_attr::NORMAL,
71 term_color::_ fg = term_color::ORIGINAL,
72 term_color::_ bg = term_color::ORIGINAL )
74 m_command_size = std::sprintf( m_control_command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40 );
78 operator<<( std::ostream& os, setcolor const& sc )
80 return os.write( sc.m_control_command, sc.m_command_size );
85 char m_control_command[13];
89 // ************************************************************************** //
90 // ************** scope_setcolor ************** //
91 // ************************************************************************** //
93 struct scope_setcolor {
94 scope_setcolor() : m_os( 0 ) {}
95 explicit scope_setcolor( std::ostream& os,
96 term_attr::_ attr = term_attr::NORMAL,
97 term_color::_ fg = term_color::ORIGINAL,
98 term_color::_ bg = term_color::ORIGINAL )
101 os << setcolor( attr, fg, bg );
113 #define BOOST_TEST_SCOPE_SETCOLOR( is_color_output, os, attr, color ) \
114 utils::scope_setcolor const& sc = is_color_output \
115 ? utils::scope_setcolor( os, utils::attr, utils::color ) \
116 : utils::scope_setcolor(); \
117 ut_detail::ignore_unused_variable_warning( sc ) \
121 } // namespace unit_test
124 #include <boost/test/detail/enable_warnings.hpp>
126 #endif // BOOST_TEST_UTILS_SETCOLOR_HPP