C++ Utilities  4.10.0
Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities
Enumerations | Functions
EscapeCodes Namespace Reference

Encapsulates functions for formatted terminal output using ANSI escape codes. More...

Enumerations

enum  Color : char {
  Color::Black = '0', Color::Red, Color::Green, Color::Yellow,
  Color::Blue, Color::Purple, Color::Cyan, Color::White
}
 
enum  ColorContext : char { ColorContext::Foreground = '3', ColorContext::Background = '4' }
 
enum  TextAttribute : char {
  TextAttribute::Reset = '0', TextAttribute::Bold = '1', TextAttribute::Dim = '2', TextAttribute::Italic = '3',
  TextAttribute::Underscore = '4', TextAttribute::Blink = '5', TextAttribute::ReverseVideo = '7', TextAttribute::Concealed = '8'
}
 
enum  Direction : char { Direction::Up = 'A', Direction::Down = 'B', Direction::Forward = 'C', Direction::Backward = 'D' }
 
enum  Phrases {
  Phrases::Error, Phrases::Warning, Phrases::End, Phrases::PlainMessage,
  Phrases::SuccessMessage, Phrases::SubMessage, Phrases::ErrorMessage, Phrases::WarningMessage
}
 The Phrases enum contains standard phrases which can be printed to any std::ostream. More...
 

Functions

void setStyle (std::ostream &stream, TextAttribute displayAttribute=TextAttribute::Reset)
 
void setStyle (std::ostream &stream, Color color, ColorContext context=ColorContext::Foreground, TextAttribute displayAttribute=TextAttribute::Reset)
 
void setStyle (std::ostream &stream, Color foregroundColor, Color backgroundColor, TextAttribute displayAttribute=TextAttribute::Reset)
 
void resetStyle (std::ostream &stream)
 
void setCursor (std::ostream &stream, unsigned int row=0, unsigned int col=0)
 
void moveCursor (std::ostream &stream, unsigned int cells, Direction direction)
 
void saveCursor (std::ostream &stream)
 
void restoreCursor (std::ostream &stream)
 
void eraseDisplay (std::ostream &stream)
 
void eraseLine (std::ostream &stream)
 
std::ostream & operator<< (std::ostream &stream, TextAttribute displayAttribute)
 
auto color (Color foreground, Color background, TextAttribute displayAttribute=TextAttribute::Reset)
 
std::ostream & operator<< (std::ostream &stream, std::tuple< Color, Color, TextAttribute > displayAttribute)
 
CPP_UTILITIES_EXPORT std::ostream & operator<< (std::ostream &stream, Phrases phrase)
 Prints the specified phrase. More...
 

Detailed Description

Encapsulates functions for formatted terminal output using ANSI escape codes.

Remarks
The functions haven't been tested yet and are still experimental. API/ABI might change in next minor release.

Enumeration Type Documentation

◆ Color

enum EscapeCodes::Color : char
strong
Enumerator
Black 
Red 
Green 
Yellow 
Blue 
Purple 
Cyan 
White 

Definition at line 15 of file ansiescapecodes.h.

◆ ColorContext

enum EscapeCodes::ColorContext : char
strong
Enumerator
Foreground 
Background 

Definition at line 17 of file ansiescapecodes.h.

◆ Direction

enum EscapeCodes::Direction : char
strong
Enumerator
Up 
Down 
Forward 
Backward 

Definition at line 30 of file ansiescapecodes.h.

◆ Phrases

enum EscapeCodes::Phrases
strong

The Phrases enum contains standard phrases which can be printed to any std::ostream.

Example: std::cerr << Phrases::Error << "Something bad happened." << Phrases::End

Enumerator
Error 

bold, red "Error: "

Warning 

bold, yellow "Warning: "

End 

resets the style

PlainMessage 

bold, 4 spaces " "

SuccessMessage 

bold, green "==> "

SubMessage 

bold, blue " -> "

ErrorMessage 

bold, red "==> ERROR: "

WarningMessage 

bold, yellow "==> WARNING: "

Definition at line 106 of file ansiescapecodes.h.

◆ TextAttribute

enum EscapeCodes::TextAttribute : char
strong
Enumerator
Reset 
Bold 
Dim 
Italic 
Underscore 
Blink 
ReverseVideo 
Concealed 

Definition at line 19 of file ansiescapecodes.h.

Function Documentation

◆ color()

auto EscapeCodes::color ( Color  foreground,
Color  background,
TextAttribute  displayAttribute = TextAttribute::Reset 
)
inline

Definition at line 90 of file ansiescapecodes.h.

◆ eraseDisplay()

void EscapeCodes::eraseDisplay ( std::ostream &  stream)
inline

Definition at line 74 of file ansiescapecodes.h.

◆ eraseLine()

void EscapeCodes::eraseLine ( std::ostream &  stream)
inline

Definition at line 79 of file ansiescapecodes.h.

◆ moveCursor()

void EscapeCodes::moveCursor ( std::ostream &  stream,
unsigned int  cells,
Direction  direction 
)
inline

Definition at line 59 of file ansiescapecodes.h.

◆ operator<<() [1/3]

std::ostream& EscapeCodes::operator<< ( std::ostream &  stream,
TextAttribute  displayAttribute 
)
inline

Definition at line 84 of file ansiescapecodes.h.

◆ operator<<() [2/3]

std::ostream& EscapeCodes::operator<< ( std::ostream &  stream,
std::tuple< Color, Color, TextAttribute displayAttribute 
)
inline

Definition at line 95 of file ansiescapecodes.h.

◆ operator<<() [3/3]

std::ostream & EscapeCodes::operator<< ( std::ostream &  stream,
Phrases  phrase 
)

Prints the specified phrase.

Definition at line 8 of file ansiescapecodes.cpp.

◆ resetStyle()

void EscapeCodes::resetStyle ( std::ostream &  stream)
inline

Definition at line 49 of file ansiescapecodes.h.

◆ restoreCursor()

void EscapeCodes::restoreCursor ( std::ostream &  stream)
inline

Definition at line 69 of file ansiescapecodes.h.

◆ saveCursor()

void EscapeCodes::saveCursor ( std::ostream &  stream)
inline

Definition at line 64 of file ansiescapecodes.h.

◆ setCursor()

void EscapeCodes::setCursor ( std::ostream &  stream,
unsigned int  row = 0,
unsigned int  col = 0 
)
inline

Definition at line 54 of file ansiescapecodes.h.

◆ setStyle() [1/3]

void EscapeCodes::setStyle ( std::ostream &  stream,
TextAttribute  displayAttribute = TextAttribute::Reset 
)
inline

Definition at line 32 of file ansiescapecodes.h.

◆ setStyle() [2/3]

void EscapeCodes::setStyle ( std::ostream &  stream,
Color  color,
ColorContext  context = ColorContext::Foreground,
TextAttribute  displayAttribute = TextAttribute::Reset 
)
inline

Definition at line 37 of file ansiescapecodes.h.

◆ setStyle() [3/3]

void EscapeCodes::setStyle ( std::ostream &  stream,
Color  foregroundColor,
Color  backgroundColor,
TextAttribute  displayAttribute = TextAttribute::Reset 
)
inline

Definition at line 43 of file ansiescapecodes.h.