ComPPare 1.0.0
|
This file contains utilities for applying ANSI styles and colors to console output. More...
Go to the source code of this file.
Classes | |
class | comppare::internal::ansi::ScopedAnsiWrapper< T > |
Applying ANSI styles/colors to a value in a scope. More... | |
Namespaces | |
namespace | comppare::internal::ansi |
Utilities for applying ANSI styles and colors to console output. | |
namespace | comppare |
ComPPare framework main namespace. | |
namespace | comppare::internal |
Macros | |
#define | ANSI_DEFINE(NAME, ON, OFF) |
Macro to define ANSI escape codes for text styling and colors. | |
This file contains utilities for applying ANSI styles and colors to console output.
This file supports two usage patterns for formatting console output with ANSI escape codes:
<<
)._OFF
code.BOLD
/ BOLD_OFF
, RED_
/ RED_OFF
.RED("Red")
.RESET
can be used to reset all styles and colors to default. std::cout << comppare::internal::ansi::BOLD << comppare::internal::ansi::RED << "Bold Red" << comppare::internal::ansi::RESET << " Back to normal"; #define ANSI_DEFINE | ( | NAME, | |
ON, | |||
OFF | |||
) |
Macro to define ANSI escape codes for text styling and colors.
This macro generates a pair of classes and its instances to represent an ANSI style or color. The resulting API supports both:
Example with the style BOLD
:
NAME##_ON_CODE
→ string literal for enabling ("\033[1m"
)NAME##_OFF_CODE
→ string literal for disabling ("\033[22m"
) ECMA-48 “Select Graphic Rendition” (SGR) sequences are defined here: https://man7.org/linux/man-pages/man4/console_codes.4.htmlON class (NAME##_ON_t
)
operator<<
— inserts the ON code directly into an ostream
operator()
— wraps a value in a ScopedAnsiWrapper
, which streams ON + value + OFF
automaticallyInstance:
Users actually call this instance, not the class itself:
OFF class (NAME##_OFF_t
)
operator<<
— inserts the OFF code directly into an ostream
Instance:
Usage:
NAME | The identifier to generate (BOLD , RED , etc.) |
ON | Numeric ANSI code to enable |
OFF | Numeric ANSI code to disable/reset |