Porytiles
Loading...
Searching...
No Matches
porytiles::FormatParam Class Reference

A text parameter with associated styling for formatted output. More...

#include <text_formatter.hpp>

Public Member Functions

 FormatParam (std::string text)
 Constructs a FormatParam with unstyled text.
 
 FormatParam (std::string text, Style styles)
 Constructs a FormatParam with styled text.
 
template<typename T >
requires ( !std::is_same_v<std::decay_t<T>, std::string> && !std::is_same_v<std::decay_t<T>, FormatParam> && std::formattable<std::decay_t<T>, char>)
 FormatParam (T &&value)
 Constructs a FormatParam by converting a value to string.
 
template<typename T >
requires ( !std::is_same_v<std::decay_t<T>, std::string> && !std::is_same_v<std::decay_t<T>, FormatParam> && std::formattable<std::decay_t<T>, char>)
 FormatParam (T &&value, Style styles)
 Constructs a FormatParam by converting a value to styled string.
 
const std::string & text () const
 
Style styles () const
 

Detailed Description

A text parameter with associated styling for formatted output.

FormatParam pairs a text string with Style flags to enable styled parameter substitution in formatted strings. When used with TextFormatter::format(), the text is styled according to the formatter implementation (ANSI codes for TTY, plain text for non-TTY) before being substituted into the format string.

Example usage:

++
FormattableError{"tileset '{}' not found", FormatParam{name, Style::bold}}
A text parameter with associated styling for formatted output.
General-purpose error implementation with formatted message support.
Definition error.hpp:63
static const Style bold
Bold text formatting.

This struct is typically constructed inline when creating error messages or formatted diagnostic output.

Definition at line 417 of file text_formatter.hpp.

Constructor & Destructor Documentation

◆ FormatParam() [1/4]

porytiles::FormatParam::FormatParam ( std::string  text)
inline

Constructs a FormatParam with unstyled text.

Creates a FormatParam with the given text and no styling applied (Style::none).

Parameters
textThe text content to be formatted

Definition at line 427 of file text_formatter.hpp.

◆ FormatParam() [2/4]

porytiles::FormatParam::FormatParam ( std::string  text,
Style  styles 
)
inlineexplicit

Constructs a FormatParam with styled text.

Creates a FormatParam with the given text and specified styling attributes.

Parameters
textThe text content to be formatted
stylesThe styling attributes to apply to the text

Definition at line 438 of file text_formatter.hpp.

◆ FormatParam() [3/4]

template<typename T >
requires ( !std::is_same_v<std::decay_t<T>, std::string> && !std::is_same_v<std::decay_t<T>, FormatParam> && std::formattable<std::decay_t<T>, char>)
porytiles::FormatParam::FormatParam ( T &&  value)
inline

Constructs a FormatParam by converting a value to string.

Creates a FormatParam by converting the given value to a string using std::format. This constructor is constrained to accept types that satisfy std::formattable<T, char>, excluding std::string to avoid ambiguity with the existing string constructor.

Template Parameters
TThe type of the value (must satisfy std::formattable<T, char>)
Parameters
valueThe value to convert to string

Definition at line 455 of file text_formatter.hpp.

◆ FormatParam() [4/4]

template<typename T >
requires ( !std::is_same_v<std::decay_t<T>, std::string> && !std::is_same_v<std::decay_t<T>, FormatParam> && std::formattable<std::decay_t<T>, char>)
porytiles::FormatParam::FormatParam ( T &&  value,
Style  styles 
)
inlineexplicit

Constructs a FormatParam by converting a value to styled string.

Creates a FormatParam by converting the given value to a string using std::format, with the specified styling attributes applied.

Template Parameters
TThe type of the value (must satisfy std::formattable<T, char>)
Parameters
valueThe value to convert to string
stylesThe styling attributes to apply to the text

Definition at line 474 of file text_formatter.hpp.

Member Function Documentation

◆ styles()

Style porytiles::FormatParam::styles ( ) const
inline

Definition at line 483 of file text_formatter.hpp.

◆ text()

const std::string & porytiles::FormatParam::text ( ) const
inline

Definition at line 478 of file text_formatter.hpp.


The documentation for this class was generated from the following file: