Color#
ANSI escape sequence related functions and facilities.
Info
To use declarations from this page, include the <essence/color.hpp> header.
They are found within the essence::ansi namespace.
-
using sequence = std::string_view#
A distinctly-named type for predefined ansi escape sequences.
Constant |
Resetter |
Description |
|---|---|---|
|
N/A |
Reset all formatting |
|
|
Bolden text |
|
|
Dim the text |
|
|
Italicize text |
|
|
Underline the text |
|
|
Periodically blink between hidden and visible |
|
|
Make text invisible |
|
|
Add a strike-through line to the text |
|
|
Colorize foreground text, where |
|
|
Colorize background of cells, where |
|
|
Colorize foreground text with a bright variant of |
|
|
Colorize background of cells with a bright variant of |
-
std::regex escape_rx#
A regex useful for capturing standard ansi escape sequences.
-
void strip(std::string &in)#
Strip ansi escape sequences from a string (in-place).
Utilizes the escape_rx regex to perform the strip.
-
std::string cstrip(std::string_view in)#
Strip ansi escape sequences from a string (copying).
Utilizes the escape_rx regex to perform the strip.
-
template<typename T>
concept Appendable# A type that can be appended to a message instance.
Valid Expressions
-
template<typename T>
concept StringLike# A string-like type.
Valid Expressions
-
class message#
A wrapped std::string facilitating easy colorization and formatting.
Example
#include <essence/io.hpp> #include <essence/color.hpp> int main() { using namespace essence::ansi; // print ' Hello! ' with black text on a green background, in a bold and italic face. message m = fg::black|bg::green|italic|bold|" Hello! "|none; io::printn(m); return 0; }
-
message::message(std::string s)#
Construct a message from a std::string. The constructor may also be called with a const char*, std::string_view, const std::string& or a sequence.
-
template<Appendable T>
message &append(T &t)# Append an Appendable type to a message. May also be called with a constant
Treference.
-
template<StringLike... Args>
requires (sizeof...(Args) >= 2)
message &append(Args&&... args)# Append multiple StringLike types to a message.
Example
using namespace essence::ansi; message m; m.append(fg::black, bg::green, bold, italic, " Hello ", none);
-
message &strip()#
Remove all ansi escape sequences from the underlying std::string using the ansi::strip function and ansi::escape_rx regex.
-
std::string str() const#
Get a copy of the string content.
-
template<Appendable T>
friend message operator+(const message &lhs, T rhs)# Addition operator for Appendable types.
-
friend std::ostream &operator<<(std::ostream &os, const message &self)#
Stream overload for std::cout and the like.
-
operator std::string() const#
Implicit conversion operator to produce a std::string.
-
message::message(std::string s)#
-
message &operator+=(message &lhs, std::string rhs)#
Addition-equal overload to append a std::string to a message.
-
std::string &operator|(std::string &lhs, sequence rhs)#
Bitwise-or overload to append a sequence to a string.
-
std::string &operator|=(std::string &lhs, sequence rhs)#
Bitwise-or assignment overload to append a sequence to a string.
-
std::string operator+(sequence a, sequence b)#
Addition overload which constructs a string from two sequences.
-
std::string &operator+=(std::string &lhs, sequence rhs)#
Addition-assignment overload to append a sequence to a string.
-
std::string operator|(sequence a, sequence b)#
Bitwise-or overload to construct a string from two sequences.
-
std::string operator|(std::string &&lhs, sequence rhs)#
Bitwise-or overload to construct a string from an
rvaluestring and a sequence.
-
std::string operator|(std::string &&lhs, const char *rhs)#
Bitwise-or overload to construct a string from an
rvaluestring and a const char*.