libzypp: ztui::ansi::Color Class Reference

libzypp 17.38.15

ztui::ansi::Color Class Reference

Various ways to define ansi SGR sequences. More...

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

## Classes
union | Comp

## Public Types
enum class | Attr : std::uint8_t { Unchanged , Normal , Bright , Reverse }
| Color attributes. More...
enum class | Fg : std::uint8_t { Unchanged , Default , Black , Red , Green , Yellow , Blue , Magenta , Cyan , White }
| Foreground colors. More...
enum class | Bg : std::uint8_t { Unchanged , Default , Black , Red , Green , Yellow , Blue , Magenta , Cyan , White }
| Backgroud colors. More...
enum | Constant : std::uint8_t { Black , BrightBlack , Red , BrightRed , Green , BrightGreen , Yellow , BrightYellow , Blue , BrightBlue , Magenta , BrightMagenta , Cyan , BrightCyan , White , BrightWhite , Default , BrightDefault }
| Predefined (foregreound) color contants Intentionally not an enum class, so it can be used as `Color::Red`, `Color::Default`, etc. More...
using | UidType = std::uint32_t
| Color unique id type.

## Public Member Functions
| Color ()
| Default ctor: terminal default color.
| Color (Attr attr_r, Fg fg_r=Fg::Unchanged, Bg bg_r=Bg::Unchanged)
| Color (Attr attr_r, Bg bg_r)
| Color (Fg fg_r, Bg bg_r=Bg::Unchanged)
| Color (Bg bg_r)
| Color (Constant color_r, Bg bg_r=Bg::Default)
| Color constant combined with background (Bg::Default).
template<class CCC_, typename = EnableIfCustomColorCtor<CCC_>>
| Color (CCC_ &&color_r)
| Custom ctor from ColorTraits enabled type.
| operator bool () const
| Evaluate in boolean context (not nocolor).
Color & | operator<= (Color rhs)
| Update Color (assign components which are not `Unchanged` in rhs ).
Color & | operator<= (Color::Attr rhs)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Color & | operator<= (Color::Fg rhs)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Color & | operator<= (Color::Bg rhs)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Color & | operator<= (Color::Constant rhs)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Color | operator< (Color rhs) const
| Return updated color.
Color | operator< (Color::Attr rhs) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Color | operator< (Color::Fg rhs) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Color | operator< (Color::Bg rhs) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Color | operator< (Color::Constant rhs) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Attr | attr () const
Color & | attr (Attr attr_r)
Fg | fg () const
Color & | fg (Fg fg_r)
Bg | bg () const
Color & | bg (Bg bg_r)
UidType | uid () const
| Each color has a unique numeric id.
const std::string & | str () const
| The colors SGRsequence if do_colors is `true`.
std::string | debugstr () const
| The colors SGRsequence human readable.

## Static Public Member Functions
static Color | nocolor ()
| Leave everything unchanged.
static Color | fromString (const std::string &colorName)
static const std::string & | SGRReset ()
| ANSI SGR sesquence to reset all attributes.

## Private Member Functions
| Color (UidType)
| ctor nocolor, all ::Unchanged, uid 0

## Static Private Member Functions
static std::string & | genSGR (Color color_r)
| Return a colors SGRsequence if do_colors retruns `true`.

## Private Attributes
union ztui::ansi::Color::Comp | _comp

## Friends
bool | operator== (Color lhs, Color rhs)
| relates: Color
bool | operator!= (Color lhs, Color rhs)
| relates: Color

## Detailed Description

Various ways to define ansi SGR sequences.

Any color component (Attr, Fg, Bg) may have the value `Uchanged`, indicating that this component should remain unchanged when the terminal color is set. To mimic this use operator<<= which updates a color by omitting `Unchanged` components. nocolor

Note
  The function do_colors determines if ansi SGR sequences are generated for colors at all.

Definition at line 172 of file ansi.h.

## Member Typedef Documentation

## ◆ UidType

using ztui::ansi::Color::UidType = std::uint32_t

Color unique id type.

Definition at line 188 of file ansi.h.

## Member Enumeration Documentation

## ◆ Attr

enum class ztui::ansi::Color::Attr : std::uint8_t
| strong

Color attributes.

Enumerator
Unchanged |
Normal |
Bright |
Reverse |

Definition at line 176 of file ansi.h.

## ◆ Fg

enum class ztui::ansi::Color::Fg : std::uint8_t
| strong

Foreground colors.

Enumerator
Unchanged |
Default |
Black |
Red |
Green |
Yellow |
Blue |
Magenta |
Cyan |
White |

Definition at line 180 of file ansi.h.

## ◆ Bg

enum class ztui::ansi::Color::Bg : std::uint8_t
| strong

Backgroud colors.

Enumerator
Unchanged |
Default |
Black |
Red |
Green |
Yellow |
Blue |
Magenta |
Cyan |
White |

Definition at line 184 of file ansi.h.

## ◆ Constant

enum ztui::ansi::Color::Constant : std::uint8_t

Predefined (foregreound) color contants Intentionally not an enum class, so it can be used as `Color::Red`, `Color::Default`, etc.

Enumerator
Black |
BrightBlack |
Red |
BrightRed |
Green |
BrightGreen |
Yellow |
BrightYellow |
Blue |
BrightBlue |
Magenta |
BrightMagenta |
Cyan |
BrightCyan |
White |
BrightWhite |
Default |
BrightDefault |

Definition at line 194 of file ansi.h.

## Constructor & Destructor Documentation

## ◆ Color() [1/8]

ztui::ansi::Color::Color | ( |  | ) |
| inline

Default ctor: terminal default color.

Definition at line 209 of file ansi.h.

## ◆ Color() [2/8]

ztui::ansi::Color::Color | ( | Attr | attr_r,
|  | Fg | fg_r = Fg::Unchanged,
|  | Bg | bg_r = Bg::Unchanged )
| inline

Definition at line 213 of file ansi.h.

## ◆ Color() [3/8]

ztui::ansi::Color::Color | ( | Attr | attr_r,
|  | Bg | bg_r )
| inline

Definition at line 217 of file ansi.h.

## ◆ Color() [4/8]

ztui::ansi::Color::Color | ( | Fg | fg_r,
|  | Bg | bg_r = Bg::Unchanged )
| inline

Definition at line 221 of file ansi.h.

## ◆ Color() [5/8]

ztui::ansi::Color::Color | ( | Bg | bg_r | ) |
| inline

Definition at line 225 of file ansi.h.

## ◆ Color() [6/8]

ztui::ansi::Color::Color | ( | Constant | color_r,
|  | Bg | bg_r = Bg::Default )
| inline

Color constant combined with background (Bg::Default).

Definition at line 230 of file ansi.h.

## ◆ Color() [7/8]

template<class CCC_, typename = EnableIfCustomColorCtor<CCC_>>

ztui::ansi::Color::Color | ( | CCC_ && | color_r | ) |
| inline

Custom ctor from ColorTraits enabled type.

Definition at line 259 of file ansi.h.

## ◆ Color() [8/8]

ztui::ansi::Color::Color | ( | UidType |  | ) |
| inlineprivate

ctor nocolor, all ::Unchanged, uid 0

Definition at line 447 of file ansi.h.

## Member Function Documentation

## ◆ nocolor()

Color ztui::ansi::Color::nocolor | ( |  | ) |
| inlinestatic

Leave everything unchanged.

Definition at line 265 of file ansi.h.

## ◆ fromString()

Color ztui::ansi::Color::fromString | ( | const std::string & | colorName | ) |
| static

Returns the Color corresponding to the colorName. If colorName does not match a known string this returns the same as nocolor.

Color::fromString("bold red");
ztui::ansi::Color::fromString
static Color fromString(const std::string &colorName)
Definition colors.cc:68

Definition at line 68 of file colors.cc.

## ◆ operator bool()

ztui::ansi::Color::operator bool | ( |  | ) | const
| inlineexplicit

Evaluate in boolean context (not nocolor).

Definition at line 281 of file ansi.h.

## ◆ SGRReset()

const std::string & ztui::ansi::Color::SGRReset | ( |  | ) |
| inlinestatic

ANSI SGR sesquence to reset all attributes.

Note
  Printing this SGR sequence has the same visible effect as setting Color::Default. Classes supporting re-coloring, like ColorString, however differ between both. While Color::Default is a color to use, thus to keep when re-coloring, SGRReset is used as placeholder for later coloring.

Definition at line 291 of file ansi.h.

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

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

Update Color (assign components which are not `Unchanged` in rhs ).

Definition at line 305 of file ansi.h.

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

Color & ztui::ansi::Color::operator<= | ( | Color::Attr | rhs | ) |
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 313 of file ansi.h.

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

Color & ztui::ansi::Color::operator<= | ( | Color::Fg | rhs | ) |
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 316 of file ansi.h.

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

Color & ztui::ansi::Color::operator<= | ( | Color::Bg | rhs | ) |
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 319 of file ansi.h.

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

Color & ztui::ansi::Color::operator<= | ( | Color::Constant | rhs | ) |
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 473 of file ansi.h.

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

Color ztui::ansi::Color::operator< | ( | Color | rhs | ) | const
| inline

Return updated color.

Definition at line 325 of file ansi.h.

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

Color ztui::ansi::Color::operator< | ( | Color::Attr | rhs | ) | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 328 of file ansi.h.

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

Color ztui::ansi::Color::operator< | ( | Color::Fg | rhs | ) | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 331 of file ansi.h.

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

Color ztui::ansi::Color::operator< | ( | Color::Bg | rhs | ) | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 334 of file ansi.h.

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

Color ztui::ansi::Color::operator< | ( | Color::Constant | rhs | ) | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 474 of file ansi.h.

## ◆ attr() [1/2]

Attr ztui::ansi::Color::attr | ( |  | ) | const
| inline

Definition at line 340 of file ansi.h.

## ◆ attr() [2/2]

Color & ztui::ansi::Color::attr | ( | Attr | attr_r | ) |
| inline

Definition at line 343 of file ansi.h.

## ◆ fg() [1/2]

Fg ztui::ansi::Color::fg | ( |  | ) | const
| inline

Definition at line 346 of file ansi.h.

## ◆ fg() [2/2]

Color & ztui::ansi::Color::fg | ( | Fg | fg_r | ) |
| inline

Definition at line 349 of file ansi.h.

## ◆ bg() [1/2]

Bg ztui::ansi::Color::bg | ( |  | ) | const
| inline

Definition at line 352 of file ansi.h.

## ◆ bg() [2/2]

Color & ztui::ansi::Color::bg | ( | Bg | bg_r | ) |
| inline

Definition at line 355 of file ansi.h.

## ◆ uid()

UidType ztui::ansi::Color::uid | ( |  | ) | const
| inline

Each color has a unique numeric id.

Definition at line 359 of file ansi.h.

## ◆ str()

const std::string & ztui::ansi::Color::str | ( |  | ) | const
| inline

The colors SGRsequence if do_colors is `true`.

Definition at line 363 of file ansi.h.

## ◆ debugstr()

std::string ztui::ansi::Color::debugstr | ( |  | ) | const
| inline

The colors SGRsequence human readable.

Definition at line 367 of file ansi.h.

## ◆ genSGR()

std::string & ztui::ansi::Color::genSGR | ( | Color | color_r | ) |
| inlinestaticprivate

Return a colors SGRsequence if do_colors retruns `true`.

Definition at line 381 of file ansi.h.

## Friends And Related Symbol Documentation

## ◆ operator==

bool operator== | ( | Color | lhs,
|  | Color | rhs )
| friend

relates: Color

Definition at line 372 of file ansi.h.

## ◆ operator!=

bool operator!= | ( | Color | lhs,
|  | Color | rhs )
| friend

relates: Color

Definition at line 376 of file ansi.h.

## Member Data Documentation

## ◆ _comp

union ztui::ansi::Color::Comp ztui::ansi::Color::_comp
| private

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

- zypp-tui/utils/ansi.h
- zypp-tui/utils/colors.cc