libzypp 17.37.10

ColorTraits< Tp_ > Class Reference

Traits class to enable custom Color construction. More...

`#include <zypp-tui/utils/ansi.h>`

## Detailed Description

Traits class to enable custom Color construction.

This enables using user types (usaually enums) to be used as Color with ColorString or ColorStream classes:

enum ColorContext { Red, Green, Blue };
cout << "default"
<< ( ColorContext::Green << "green"
<< ColorContext::Red << "switch to red"
<< ( ColorContext::Blue << "blue" )
<< "still red" )
<< "default" << endl;

You need to define a function ansi::Color customColorCtor( EnumType enum_r ) which associates enum value and Color:

ansi::Color customColorCtor( ColorContext ctxt_r )
{ return Color associated with each enum value }

Then specailize ColorTraits for your enum to enable using it as ColorStream

namespace ansi
{
template<>
struct ColorTraits<ColorContext>
{ enum { customColorCtor = true }; };
}

This will enable your enum being impicitly converted into ansi::Color, especially when used together with ColorString and ColorStream. Printing your enum on a stream, will also print the associated colors SGR sequence:

// provided via ColorTraits:
std::ostream & operator<<( std::ostream & str, ColorContext obj )
{ return str << ansi::Color( obj ); }
operator<<
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
Definition LookupAttr.cc:808
str
String related utilities and Regular expression matching.

The documentation for this class was generated from the following file:

- zypp-tui/utils/ansi.h