libzypp: ztui::ansi::ColorStream Class Reference

libzypp 17.38.11

ztui::ansi::ColorStream Class Reference

Colored stream output if do_colors. More...

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

## Classes
struct | nullDeleter

## Public Member Functions
| ColorStream ()
| Default Ctor (Color::Default).
| ColorStream (Color color_r)
| Ctor taking a Color.
| ColorStream (std::ostream &direct_r)
| Ctor directly printing to a std::ostream (Color::Default).
| ColorStream (std::ostream &direct_r, Color color_r)
| Ctor directly printing to a std::ostream in Color.
| ColorStream (const ColorStream &)=delete
| non copyable
ColorStream & | operator= (const ColorStream &)=delete
| ColorStream (ColorStream &&)=default
| movable
ColorStream & | operator= (ColorStream &&)=default
| ~ColorStream ()
| operator std::ostream & ()
| Explicit conversion to std::ostream (creates buffer if not direct).
ColorStream & | operator= (Color color_r)
| Change the streams Color.
ColorStream & | operator<= (Color color_r)
| Update the streams Color.
Color | color () const
| Return streams Color.
std::string | str () const
| Return a buffered streams content as (colored) string.
ColorStream & | operator<< (Color color_r)
| Printing a Color (also via enum) updates the streams Color.
ColorStream & | operator<< (const ColorString &val_r)
| Printing a ColorString using his Color.
ColorStream & | operator<< (const ColorStream &val_r)
| Printing another ColorStream using his Color.
template<class Tp_, typename = DisableIfCustomColorCtor<Tp_>>
ColorStream & | operator<< (const Tp_ &val_r)
| All other types are printed via std::ostream.
ColorStream & | operator<< (std::ostream &(*omanip)(std::ostream &))

## Private Member Functions
bool | hasStream () const
| Direct or non-empty buffer.
std::ostream & | stream () const
| Reference to the underlying ostream (direct or auto-created buffer).
bool | hasContent () const
| Non-empty buffer (implies direct).
std::string | content () const
| Content of a non-empty buffered stream or empty.

## Private Attributes
std::unique_ptr< std::ostream, nullDeleter > | _directP
std::unique_ptr< std::ostringstream > | _bufferP
Color | _color

## Friends
std::ostream & | operator<< (std::ostream &str, const ColorStream &obj)
| relates: ColorStream Print colored on ostream

## Detailed Description

Colored stream output if do_colors.

handling via an enum type.

If an `ostream&` is passed to the constructor, we directly print to this steam. Otherwise an ostringstream is used as buffer until the buffered ColorStream itself is printed. Printing an unbuffered steam prints an empty string.

Note
  Printing directly to a stream, the color is active throughout the ColorStreams lifetime (set in ctor, reset in dtor).

See also
  ColorTraits<Tp_> for how to enable convenient

ColorStream cstr( std::move( ColorContext::Red << "Error " << 42 ) );
cout << "default"
<< ( ColorContext::Green << "prints green"
<< ColorContext::Red << "switch to red"
<< ( ColorContext::Blue << "prints blue" )
<< "still prints red" )
<< "default" << endl;
ztui::ansi::ColorStream::ColorStream
ColorStream()
Default Ctor (Color::Default).
Definition ansi.h:679

Note
  This class is not copyable but movable.

Definition at line 673 of file ansi.h.

## Constructor & Destructor Documentation

## ◆ ColorStream() [1/6]

ztui::ansi::ColorStream::ColorStream | ( |  | ) |
| inline

Default Ctor (Color::Default).

Definition at line 679 of file ansi.h.

## ◆ ColorStream() [2/6]

ztui::ansi::ColorStream::ColorStream | ( | Color | color_r | ) |
| inlineexplicit

Ctor taking a Color.

Definition at line 683 of file ansi.h.

## ◆ ColorStream() [3/6]

ztui::ansi::ColorStream::ColorStream | ( | std::ostream & | direct_r | ) |
| inlineexplicit

Ctor directly printing to a std::ostream (Color::Default).

Definition at line 688 of file ansi.h.

## ◆ ColorStream() [4/6]

ztui::ansi::ColorStream::ColorStream | ( | std::ostream & | direct_r,
|  | Color | color_r )
| inline

Ctor directly printing to a std::ostream in Color.

Definition at line 693 of file ansi.h.

## ◆ ColorStream() [5/6]

ztui::ansi::ColorStream::ColorStream | ( | const ColorStream & |  | ) |
| delete

non copyable

## ◆ ColorStream() [6/6]

ztui::ansi::ColorStream::ColorStream | ( | ColorStream && |  | ) |
| default

movable

## ◆ ~ColorStream()

ztui::ansi::ColorStream::~ColorStream | ( |  | ) |
| inline

Definition at line 706 of file ansi.h.

## Member Function Documentation

## ◆ operator=() [1/3]

ColorStream & ztui::ansi::ColorStream::operator= | ( | const ColorStream & |  | ) |
| delete

## ◆ operator=() [2/3]

ColorStream & ztui::ansi::ColorStream::operator= | ( | ColorStream && |  | ) |
| default

## ◆ operator std::ostream &()

ztui::ansi::ColorStream::operator std::ostream & | ( |  | ) |
| inlineexplicit

Explicit conversion to std::ostream (creates buffer if not direct).

Definition at line 710 of file ansi.h.

## ◆ operator=() [3/3]

ColorStream & ztui::ansi::ColorStream::operator= | ( | Color | color_r | ) |
| inline

Change the streams Color.

Definition at line 715 of file ansi.h.

## ◆ operator<=()

ColorStream & ztui::ansi::ColorStream::operator<= | ( | Color | color_r | ) |
| inline

Update the streams Color.

Definition at line 724 of file ansi.h.

## ◆ color()

Color ztui::ansi::ColorStream::color | ( |  | ) | const
| inline

Return streams Color.

Definition at line 734 of file ansi.h.

## ◆ str()

std::string ztui::ansi::ColorStream::str | ( |  | ) | const
| inline

Return a buffered streams content as (colored) string.

Definition at line 739 of file ansi.h.

## ◆ operator<<() [1/5]

ColorStream & ztui::ansi::ColorStream::operator<< | ( | Color | color_r | ) |
| inline

Printing a Color (also via enum) updates the streams Color.

Definition at line 752 of file ansi.h.

## ◆ operator<<() [2/5]

ColorStream & ztui::ansi::ColorStream::operator<< | ( | const ColorString & | val_r | ) |
| inline

Printing a ColorString using his Color.

Note
  ColorString in Color::nocolor is renderd in streams color

Definition at line 758 of file ansi.h.

## ◆ operator<<() [3/5]

ColorStream & ztui::ansi::ColorStream::operator<< | ( | const ColorStream & | val_r | ) |
| inline

Printing another ColorStream using his Color.

Definition at line 762 of file ansi.h.

## ◆ operator<<() [4/5]

template<class Tp_, typename = DisableIfCustomColorCtor<Tp_>>

ColorStream & ztui::ansi::ColorStream::operator<< | ( | const Tp_ & | val_r | ) |
| inline

All other types are printed via std::ostream.

Definition at line 771 of file ansi.h.

## ◆ operator<<() [5/5]

ColorStream & ztui::ansi::ColorStream::operator<< | ( | std::ostream &(* | omanip )(std::ostream &) | ) |
| inline

Definition at line 775 of file ansi.h.

## ◆ hasStream()

bool ztui::ansi::ColorStream::hasStream | ( |  | ) | const
| inlineprivate

Direct or non-empty buffer.

Definition at line 789 of file ansi.h.

## ◆ stream()

std::ostream & ztui::ansi::ColorStream::stream | ( |  | ) | const
| inlineprivate

Reference to the underlying ostream (direct or auto-created buffer).

Definition at line 793 of file ansi.h.

## ◆ hasContent()

bool ztui::ansi::ColorStream::hasContent | ( |  | ) | const
| inlineprivate

Non-empty buffer (implies direct).

Definition at line 807 of file ansi.h.

## ◆ content()

std::string ztui::ansi::ColorStream::content | ( |  | ) | const
| inlineprivate

Content of a non-empty buffered stream or empty.

Definition at line 811 of file ansi.h.

## Friends And Related Symbol Documentation

## ◆ operator<<

std::ostream & operator<< | ( | std::ostream & | str,
|  | const ColorStream & | obj )
| friend

relates: ColorStream Print colored on ostream

Definition at line 780 of file ansi.h.

## Member Data Documentation

## ◆ _directP

std::unique_ptr<std::ostream,nullDeleter> ztui::ansi::ColorStream::_directP
| private

Definition at line 820 of file ansi.h.

## ◆ _bufferP

std::unique_ptr<std::ostringstream> ztui::ansi::ColorStream::_bufferP
| mutableprivate

Definition at line 821 of file ansi.h.

## ◆ _color

Color ztui::ansi::ColorStream::_color
| private

Definition at line 822 of file ansi.h.

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

- zypp-tui/utils/ansi.h