|
Pretty Diagnostics
Create your own pretty diagnostics
|
Data Structures | |
| struct | SyledText |
| Holds a piece of text together with one or more ANSI style codes. More... | |
Enumerations | |
| enum class | Code { Reset = 0 , Bold = 1 , Dim = 2 , Italic = 3 , Underline = 4 , Blink = 5 , Reverse = 7 , Hidden = 8 , Strikethrough = 9 , FgBlack = 30 , FgRed = 31 , FgGreen = 32 , FgYellow = 33 , FgBlue = 34 , FgMagenta = 35 , FgCyan = 36 , FgWhite = 37 , FgDefault = 39 , BgBlack = 40 , BgRed = 41 , BgGreen = 42 , BgYellow = 43 , BgBlue = 44 , BgMagenta = 45 , BgCyan = 46 , BgWhite = 47 , BgDefault = 49 , FgBrightBlack = 90 , FgBrightRed = 91 , FgBrightGreen = 92 , FgBrightYellow = 93 , FgBrightBlue = 94 , FgBrightMagenta = 95 , FgBrightCyan = 96 , FgBrightWhite = 97 , BgBrightBlack = 100 , BgBrightRed = 101 , BgBrightGreen = 102 , BgBrightYellow = 103 , BgBrightBlue = 104 , BgBrightMagenta = 105 , BgBrightCyan = 106 , BgBrightWhite = 107 } |
| ANSI escape codes for text styling and coloring. More... | |
Functions | |
| std::ostream & | operator<< (std::ostream &os, Code code) |
| Outputs a single ANSI escape code to the given stream. More... | |
| template<std::size_t N> | |
| std::ostream & | operator<< (std::ostream &os, const SyledText< N > &text) |
| Outputs styled text to the given stream. More... | |
| template<typename... Codes> requires (std::conjunction_v<std::is_same<Codes, Code>...>) | |
| SyledText< sizeof...(Codes)> | STYLE (std::string_view text, Codes... codes) |
| Creates a styled text object from a text and a set of ANSI codes. More... | |
| int | color_enabled_index () |
Returns a unique std::ios_base::xalloc index used to store per-stream color enable state. More... | |
| void | set_color_enabled (std::ostream &os, bool enabled) |
| Enables or disables color output for a specific output stream. More... | |
| bool | is_color_enabled (std::ostream &os) |
| Checks whether color output is enabled for the given stream. More... | |
| bool | is_colorable (const std::ostream &os) |
| Checks whether the given output stream supports colored output. More... | |
| void | auto_enable_color (std::ostream &os) |
| Enables or disables color output for a stream based on its capability. More... | |
|
strong |
ANSI escape codes for text styling and coloring.
| void pretty_diagnostics::color::auto_enable_color | ( | std::ostream & | os | ) |
Enables or disables color output for a stream based on its capability.
Calls is_colorable(os) and enables color output if supported, otherwise disables it.
| os | Output stream to initialize |
| int pretty_diagnostics::color::color_enabled_index | ( | ) |
Returns a unique std::ios_base::xalloc index used to store per-stream color enable state.
| bool pretty_diagnostics::color::is_color_enabled | ( | std::ostream & | os | ) |
Checks whether color output is enabled for the given stream.
| os | Output stream to query |
| bool pretty_diagnostics::color::is_colorable | ( | const std::ostream & | os | ) |
Checks whether the given output stream supports colored output.
Performs a platform-specific best-effort check to determine whether the stream is connected to a terminal capable of displaying ANSI escape codes.
| os | Output stream to check |
| std::ostream & pretty_diagnostics::color::operator<< | ( | std::ostream & | os, |
| Code | code | ||
| ) |
Outputs a single ANSI escape code to the given stream.
If color output is disabled for the stream, this operation produces no output
| os | Target output stream |
| code | ANSI style or color code to emit |
| std::ostream & pretty_diagnostics::color::operator<< | ( | std::ostream & | os, |
| const SyledText< N > & | text | ||
| ) |
Outputs styled text to the given stream.
All style codes are emitted in order, followed by the text and a final reset code to restore default formatting
| N | Number of ANSI codes applied to the text |
| os | Target output stream |
| text | Styled text to be written |
| void pretty_diagnostics::color::set_color_enabled | ( | std::ostream & | os, |
| bool | enabled | ||
| ) |
Enables or disables color output for a specific output stream.
When disabled, no ANSI escape codes will be emitted for that stream
| os | Output stream to modify |
| enabled | Whether color output should be enabled |
| SyledText< sizeof...(Codes)> pretty_diagnostics::color::STYLE | ( | std::string_view | text, |
| Codes... | codes | ||
| ) |
Creates a styled text object from a text and a set of ANSI codes.
This helper enables concise and expressive syntax for applying multiple styles to a single text segment
| text | Text to be styled |
| codes | ANSI style and color codes to apply |
SyledText instance containing the provided styles and text