C++ Utilities 5.26.1
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Loading...
Searching...
No Matches
ansiescapecodes.h File Reference
#include "../global.h"
#include "../misc/traits.h"
#include <ostream>
#include <string_view>
#include <tuple>
Include dependency graph for ansiescapecodes.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  CppUtilities
 Contains all utilities provides by the c++utilities library.
 
namespace  CppUtilities::EscapeCodes
 Encapsulates functions for formatted terminal output using ANSI escape codes.
 

Enumerations

enum class  CppUtilities::EscapeCodes::Color : char {
  CppUtilities::EscapeCodes::Black = '0' , CppUtilities::EscapeCodes::Red , CppUtilities::EscapeCodes::Green , CppUtilities::EscapeCodes::Yellow ,
  CppUtilities::EscapeCodes::Blue , CppUtilities::EscapeCodes::Purple , CppUtilities::EscapeCodes::Cyan , CppUtilities::EscapeCodes::White
}
 
enum class  CppUtilities::EscapeCodes::ColorContext : char { CppUtilities::EscapeCodes::Foreground = '3' , CppUtilities::EscapeCodes::Background = '4' }
 
enum class  CppUtilities::EscapeCodes::TextAttribute : char {
  CppUtilities::EscapeCodes::Reset = '0' , CppUtilities::EscapeCodes::Bold = '1' , CppUtilities::EscapeCodes::Dim = '2' , CppUtilities::EscapeCodes::Italic = '3' ,
  CppUtilities::EscapeCodes::Underscore = '4' , CppUtilities::EscapeCodes::Blink = '5' , CppUtilities::EscapeCodes::ReverseVideo = '7' , CppUtilities::EscapeCodes::Concealed = '8' ,
  CppUtilities::EscapeCodes::Strikethrough = '9'
}
 
enum class  CppUtilities::EscapeCodes::Direction : char { CppUtilities::EscapeCodes::Up = 'A' , CppUtilities::EscapeCodes::Down = 'B' , CppUtilities::EscapeCodes::Forward = 'C' , CppUtilities::EscapeCodes::Backward = 'D' }
 
enum class  CppUtilities::EscapeCodes::Phrases {
  CppUtilities::EscapeCodes::Error , CppUtilities::EscapeCodes::Warning , CppUtilities::EscapeCodes::End , CppUtilities::EscapeCodes::PlainMessage ,
  CppUtilities::EscapeCodes::SuccessMessage , CppUtilities::EscapeCodes::SubMessage , CppUtilities::EscapeCodes::ErrorMessage , CppUtilities::EscapeCodes::WarningMessage ,
  CppUtilities::EscapeCodes::EndFlush , CppUtilities::EscapeCodes::Info , CppUtilities::EscapeCodes::Override , CppUtilities::EscapeCodes::SubError ,
  CppUtilities::EscapeCodes::SubWarning , CppUtilities::EscapeCodes::InfoMessage
}
 The Phrases enum contains standard phrases which can be printed to any std::ostream and obtained as strings via EscapeCodes::phraseString() and EscapeCodes::formattedPhraseString(). More...
 

Functions

void CppUtilities::EscapeCodes::setStyle (std::ostream &stream, TextAttribute displayAttribute=TextAttribute::Reset)
 
void CppUtilities::EscapeCodes::setStyle (std::ostream &stream, Color color, ColorContext context=ColorContext::Foreground, TextAttribute displayAttribute=TextAttribute::Reset)
 
void CppUtilities::EscapeCodes::setStyle (std::ostream &stream, Color foregroundColor, Color backgroundColor, TextAttribute displayAttribute=TextAttribute::Reset)
 
void CppUtilities::EscapeCodes::resetStyle (std::ostream &stream)
 
void CppUtilities::EscapeCodes::setCursor (std::ostream &stream, unsigned int row=0, unsigned int col=0)
 
void CppUtilities::EscapeCodes::moveCursor (std::ostream &stream, unsigned int cells, Direction direction)
 
void CppUtilities::EscapeCodes::saveCursor (std::ostream &stream)
 
void CppUtilities::EscapeCodes::restoreCursor (std::ostream &stream)
 
void CppUtilities::EscapeCodes::eraseDisplay (std::ostream &stream)
 
void CppUtilities::EscapeCodes::eraseLine (std::ostream &stream)
 
std::ostream & CppUtilities::EscapeCodes::operator<< (std::ostream &stream, TextAttribute displayAttribute)
 
constexpr auto CppUtilities::EscapeCodes::color (Color foreground, Color background, TextAttribute displayAttribute=TextAttribute::Reset)
 
constexpr auto CppUtilities::EscapeCodes::color (Color foreground, ColorContext context, TextAttribute displayAttribute=TextAttribute::Reset)
 
template<typename TupleType , Traits::EnableIfAny< std::is_same< TupleType, std::tuple< Color, Color, TextAttribute > >, std::is_same< TupleType, std::tuple< Color, ColorContext, TextAttribute > > > * = nullptr>
std::ostream & CppUtilities::EscapeCodes::operator<< (std::ostream &stream, TupleType displayAttribute)
 
CPP_UTILITIES_EXPORT std::ostream & CppUtilities::EscapeCodes::operator<< (std::ostream &stream, Phrases phrase)
 Prints the specified phrase in a formatted manner using ANSI escape codes.
 
CPP_UTILITIES_EXPORT std::string_view CppUtilities::EscapeCodes::phraseString (Phrases phrase)
 Returns a string for the specified phrase without formatting.
 
CPP_UTILITIES_EXPORT std::string_view CppUtilities::EscapeCodes::formattedPhraseString (Phrases phrase)
 Returns a string for the specified phrase which is formatted using ANSI escape codes.
 

Variables

CPP_UTILITIES_EXPORT bool CppUtilities::EscapeCodes::enabled
 Controls whether the functions inside the EscapeCodes namespace actually make use of escape codes.