|
Porytiles
|
TextFormatter implementation that applies ANSI escape codes for terminal styling. More...
#include <ansi_styled_text_formatter.hpp>
Public Member Functions | |
| std::string | style (const std::string &text, Style styles) const override |
| Applies ANSI escape codes to style text according to the specified Style flags. | |
Public Member Functions inherited from porytiles2::TextFormatter | |
| virtual | ~TextFormatter ()=default |
| virtual std::string | format (const std::string &format_str, const std::vector< FormatParam > ¶ms) const |
| Formats a string with styled parameters using fmtlib syntax. | |
| template<typename FirstParam , typename... RestParams> requires ( !std::is_same_v<std::decay_t<FirstParam>, std::vector<FormatParam>> && std::is_constructible_v<FormatParam, FirstParam> && (std::is_constructible_v<FormatParam, RestParams> && ...)) | |
| std::string | format (const std::string &format_str, FirstParam &&first, RestParams &&...rest) const |
| Formats a string with styled parameters using variadic template syntax. | |
TextFormatter implementation that applies ANSI escape codes for terminal styling.
AnsiStyledTextFormatter is a concrete implementation of TextFormatter that applies ANSI escape codes to text based on the provided Style flags. This formatter is designed for TTY output where terminal emulators can interpret ANSI codes to display colored and styled text.
Multiple style flags can be combined (e.g., Style::bold | Style::red) to produce text that has both attributes. The styled text is automatically terminated with an ANSI reset code (\033[0m) to prevent styling from bleeding into subsequent output.
Usage context:
Definition at line 25 of file ansi_styled_text_formatter.hpp.
|
overridevirtual |
Applies ANSI escape codes to style text according to the specified Style flags.
Wraps the input text with appropriate ANSI escape codes based on the provided Style flags. If Style::none is provided, the text is returned unchanged. Otherwise, the text is prefixed with ANSI codes for each set flag and suffixed with an ANSI reset code.
The ANSI codes are applied in a specific order (bold first, then colors) to ensure consistent rendering across terminal emulators.
| text | The text to style |
| styles | The Style flags specifying which attributes to apply |
Implements porytiles2::TextFormatter.
Definition at line 28 of file ansi_styled_text_formatter.cpp.