SlHelpers
Loading...
Searching...
No Matches
SlHelpers::Color Class Reference

Colorized output. More...

#include <Color.h>

Public Types

enum  C : unsigned {
  BLACK = 30 , RED = 31 , GREEN = 32 , YELLOW = 33 ,
  BLUE = 34 , MAGENTA = 35 , CYAN = 36 , WHITE = 37 ,
  COL256 = 38 , DEFAULT = 39
}
 Predefined colors.
enum  Ctrl { NoNL , NL }
 Controls for Color.

Public Member Functions

 Color (enum C c=DEFAULT) noexcept
 New Color stream (stdout) using color c.
 Color (std::ostream &os, enum C c=DEFAULT) noexcept
 New Color stream (into os) using color c.
 Color (unsigned char r, unsigned char g, unsigned char b) noexcept
 New Color stream (stdout) using an RGB color.
 Color (std::ostream &os, unsigned char r, unsigned char g, unsigned char b) noexcept
 New Color stream (into os) using an RGB color.
std::ostream & os ()
 Return current output stream.
void ctrl (Ctrl ctrl)
 Controls the stream behavior.

Static Public Member Functions

static void forceColor (bool force)
 Force color value (see forceColorValue()).
static void forceColorValue (bool value)
 If forceColor(true) was called, use of colors is bound to value.

Friends

void testColor ()

Detailed Description

Colorized output.

Use like:

using Clr = SlHelpers::Color;
Clr(std::cerr, Clr::RED) << "error";
Colorized output.
Definition Color.h:18

Constructor & Destructor Documentation

◆ Color() [1/4]

SlHelpers::Color::Color ( enum C c = DEFAULT)
inlineexplicitnoexcept

New Color stream (stdout) using color c.

Parameters
cA color from C

◆ Color() [2/4]

SlHelpers::Color::Color ( std::ostream & os,
enum C c = DEFAULT )
inlineexplicitnoexcept

New Color stream (into os) using color c.

Parameters
osOutput stream where to output
cA color from C

◆ Color() [3/4]

SlHelpers::Color::Color ( unsigned char r,
unsigned char g,
unsigned char b )
inlinenoexcept

New Color stream (stdout) using an RGB color.

Parameters
rRed
gGreen
bBlue

◆ Color() [4/4]

SlHelpers::Color::Color ( std::ostream & os,
unsigned char r,
unsigned char g,
unsigned char b )
inlinenoexcept

New Color stream (into os) using an RGB color.

Parameters
osOutput stream where to output
rRed
gGreen
bBlue

Member Function Documentation

◆ ctrl()

void SlHelpers::Color::ctrl ( Ctrl ctrl)
inline

Controls the stream behavior.

Parameters
ctrlControl character (like NoNL to not automatically emit a newline at the end)

◆ forceColor()

void SlHelpers::Color::forceColor ( bool force)
inlinestatic

Force color value (see forceColorValue()).

Parameters
forceIf set, use of colors is bound to color value set by forceColorValue()

◆ forceColorValue()

void SlHelpers::Color::forceColorValue ( bool value)
inlinestatic

If forceColor(true) was called, use of colors is bound to value.

Parameters
valueIf colors should be used

◆ os()

std::ostream & SlHelpers::Color::os ( )
inline

Return current output stream.

Returns
Output stream.

The documentation for this class was generated from the following file:
  • /home/abuild/rpmbuild/BUILD/slhelpers-20260428.f233ce9-build/slhelpers-20260428.f233ce9/include/helpers/Color.h