clutchlog 0.17
|
Color and style formatter for ANSI terminal escape sequences. More...
#include <clutchlog.h>
Color and style formatter for ANSI terminal escape sequences.
The formatter supports typographic "styles" and colors. Typographic styles are available as named tag in fmt::typo
.
The formatter supports the three ANSI modes, which are automatically selected depending the argument types:
For 16-colors mode, colors are named tag in:
The following colors are available for both foregrounds (see fmt::fg
) and backgrounds (see fmt::bg
):
For 256-colors mode, colors are expected to be passed as integers in [-1,255] or the fg::none
and bg::none
tags.
fg::none
tag as first argument.For 16M-colors mode, colors can be encoded as:
fg::none
and bg::none
tags.fg::none
tag as first argument.Definition at line 380 of file clutchlog.h.
Public Member Functions | |
fmt () | |
Empty constructor, only useful for a no-op formatter. More... | |
std::string | operator() (const std::string &msg) const |
Format the given string with the currently encoded format. More... | |
std::string | str () const |
Return the formatting code as a string. More... | |
All combination of 16-colors mode constructors with different parameters orders. | |
fmt (fg f, bg b=bg::none, typo s=typo::none) | |
fmt (fg f, typo s, bg b=bg::none) | |
fmt (bg b, fg f=fg::none, typo s=typo::none) | |
fmt (bg b, typo s, fg f=fg::none) | |
fmt (typo s, fg f=fg::none, bg b=bg::none) | |
fmt (typo s, bg b, fg f=fg::none) | |
All combination of 256-colors mode constructors with different parameters orders. | |
fmt (const short f, const short b, typo s=typo::none) | |
fmt (const short f, typo s=typo::none) | |
fmt (fg, const short b, typo s=typo::none) | |
fmt (const short f, bg, typo s=typo::none) | |
All combination of 16M-colors mode constructors with different parameters orders. | |
fmt (const short fr, const short fg, const short fb, const short gr, const short gg, const short gb, typo s=typo::none) | |
fmt (fg, const short gr, const short gg, const short gb, typo s=typo::none) | |
fmt (const short fr, const short fg, const short fb, bg, typo s=typo::none) | |
fmt (const short fr, const short fg, const short fb, typo s=typo::none) | |
fmt (const std::string &f, const std::string &b, typo s=typo::none) | |
fmt (fg, const std::string &b, typo s=typo::none) | |
fmt (const std::string &f, bg, typo s=typo::none) | |
fmt (const std::string &f, typo s=typo::none) | |
Static Public Member Functions | |
static fmt | hash (const std::string &str, const std::vector< fmt > domain={}) |
Public Attributes | |
enum clutchlog::fmt::ansi | mode |
Current ANSI color mode. | |
enum clutchlog::fmt::typo | style |
Typographic style. | |
enum clutchlog::fmt::fg | fore |
Foreground color. | |
enum clutchlog::fmt::bg | back |
Background color. | |
Protected Member Functions | |
std::ostream & | print_on (std::ostream &os) const |
Print the currently encoded format escape code on the given output stream. More... | |
Protected Attributes | |
clutchlog::fmt::fg_256 | fore_256 |
Current foreground in 256-colors mode. | |
clutchlog::fmt::bg_256 | back_256 |
Current background in 256-colors mode. | |
clutchlog::fmt::fg_16M | fore_16M |
Current foreground in 16M-colors mode. | |
clutchlog::fmt::bg_16M | back_16M |
Current background in 16M-colors mode. | |
Classes | |
struct | bg_16M |
background in 256-colors mode. More... | |
struct | bg_256 |
Background in 256-colors mode. More... | |
struct | color |
Interface class for colors representation. More... | |
struct | color_16M |
Abstract base class for 16M colors objects (24-bits ANSI). More... | |
struct | color_256 |
Abstract base class for 256 colors objects (8-bits ANSI). More... | |
struct | fg_16M |
Foreground in 256-colors mode. More... | |
struct | fg_256 |
Foreground in 256-colors mode. More... | |
Public Types | |
enum class | ansi { colors_16 = -1 , colors_256 = 5 , colors_16M = 2 } |
ANSI code configuring the available number of colors. More... | |
enum class | typo { reset = 0 , bold = 1 , underline = 4 , inverse = 7 , none = -1 } |
Typographic style codes. More... | |
enum class | fg { black = 30 , red = 31 , green = 32 , yellow = 33 , blue = 34 , magenta = 35 , cyan = 36 , white = 37 , bright_black = 90 , bright_red = 91 , bright_green = 92 , bright_yellow = 93 , bright_blue = 94 , bright_magenta = 95 , bright_cyan = 96 , bright_white = 97 , none = -1 } |
Foreground color codes. More... | |
enum class | bg { black = 40 , red = 41 , green = 42 , yellow = 43 , blue = 44 , magenta = 45 , cyan = 46 , white = 47 , bright_black = 100 , bright_red = 101 , bright_green = 102 , bright_yellow = 103 , bright_blue = 104 , bright_magenta = 105 , bright_cyan = 106 , bright_white = 107 , none = -1 } |
Background color codes. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const std::tuple< fg, bg, typo > &fbs) |
Output stream operator for a 3-tuple of 16-colors mode tags. More... | |
std::ostream & | operator<< (std::ostream &os, const typo &s) |
Output stream operator for a typo tag alone, in 16-colors mode. More... | |
std::ostream & | operator<< (std::ostream &os, const fmt &fmt) |
Output stream overload. More... | |
|
inline |
Empty constructor, only useful for a no-op formatter.
Definition at line 711 of file clutchlog.h.
Definition at line 715 of file clutchlog.h.
Definition at line 716 of file clutchlog.h.
Definition at line 717 of file clutchlog.h.
Definition at line 718 of file clutchlog.h.
Definition at line 719 of file clutchlog.h.
Definition at line 720 of file clutchlog.h.
|
inlineexplicit |
Definition at line 725 of file clutchlog.h.
|
inlineexplicit |
Definition at line 726 of file clutchlog.h.
Definition at line 727 of file clutchlog.h.
Definition at line 728 of file clutchlog.h.
|
inlineexplicit |
Definition at line 733 of file clutchlog.h.
|
inlineexplicit |
Definition at line 737 of file clutchlog.h.
|
inlineexplicit |
Definition at line 741 of file clutchlog.h.
|
inlineexplicit |
Definition at line 744 of file clutchlog.h.
|
inlineexplicit |
Definition at line 748 of file clutchlog.h.
Definition at line 750 of file clutchlog.h.
Definition at line 752 of file clutchlog.h.
|
inlineexplicit |
Definition at line 754 of file clutchlog.h.
|
inlineprotected |
Print the currently encoded format escape code on the given output stream.
Definition at line 761 of file clutchlog.h.
References back, back_16M, back_256, colors_16, colors_16M, colors_256, fore, fore_16M, fore_256, mode, and style.
Referenced by operator()(), and str().
|
inline |
Format the given string with the currently encoded format.
Allow to use a formatter as a function:
Definition at line 810 of file clutchlog.h.
References print_on().
|
inline |
Return the formatting code as a string.
Definition at line 822 of file clutchlog.h.
References print_on().
|
inlinestatic |
Definition at line 829 of file clutchlog.h.
|
friend |
Output stream overload.
Allow to use a formatter as a tag within a stream:
Definition at line 795 of file clutchlog.h.
|
strong |
ANSI code configuring the available number of colors.
Enumerator | |
---|---|
colors_16 | 16 colors mode. |
colors_256 | 256 colors mode. |
colors_16M | 16 millions ("true") colors mode. |
Definition at line 383 of file clutchlog.h.
|
strong |
Typographic style codes.
Definition at line 393 of file clutchlog.h.