25enum class Style : std::uint32_t {
50 return static_cast<Style>(
static_cast<std::uint32_t
>(lhs) |
static_cast<std::uint32_t
>(rhs));
66 return static_cast<Style>(
static_cast<std::uint32_t
>(lhs) &
static_cast<std::uint32_t
>(rhs));
166 template <
typename T>
168 !std::is_same_v<std::decay_t<T>, std::string> && !std::is_same_v<std::decay_t<T>,
FormatParam> &&
169 requires(std::ostringstream os, T val) { os << val; })
185 template <
typename T>
187 !std::is_same_v<std::decay_t<T>, std::string> && !std::is_same_v<std::decay_t<T>,
FormatParam> &&
188 requires(std::ostringstream os, T val) { os << val; })
193 [[nodiscard]]
const std::string &
text()
const
207 template <
typename T>
208 static std::string to_string_impl(T &&value)
210 std::ostringstream oss;
211 oss << std::forward<T>(value);
251 [[nodiscard]]
virtual std::string
style(
const std::string &text,
Style styles)
const = 0;
270 [[nodiscard]]
virtual std::string
271 format(
const std::string &format_str,
const std::vector<FormatParam> ¶ms)
const;
296 template <
typename FirstParam,
typename... RestParams>
298 !std::is_same_v<std::decay_t<FirstParam>, std::vector<FormatParam>> &&
299 std::is_constructible_v<FormatParam, FirstParam> &&
300 (std::is_constructible_v<FormatParam, RestParams> && ...))
301 [[nodiscard]] std::string
format(
const std::string &format_str, FirstParam &&first, RestParams &&...rest)
const
303 std::vector<FormatParam> param_vector;
304 param_vector.reserve(1 +
sizeof...(RestParams));
305 param_vector.emplace_back(std::forward<FirstParam>(first));
306 (param_vector.emplace_back(std::forward<RestParams>(rest)), ...);
307 return this->
format(format_str, param_vector);
Abstract base class for applying text styling with context-aware formatting.
virtual std::string style(const std::string &text, Style styles) const =0
Applies styling to a text string.
virtual std::string format(const std::string &format_str, const std::vector< FormatParam > ¶ms) const
Formats a string with styled parameters using fmtlib syntax.
std::string format(const std::string &format_str, FirstParam &&first, RestParams &&...rest) const
Formats a string with styled parameters using variadic template syntax.
virtual ~TextFormatter()=default
Style
Bitmask flags for text styling options.
@ italic
Italic text formatting.
@ none
No styling applied.
@ magenta
Magenta text color.
@ bold
Bold text formatting.
@ yellow
Yellow text color.
constexpr Style & operator|=(Style &lhs, Style rhs)
Adds Style flags to an existing Style value using bitwise OR.
constexpr Style operator|(Style lhs, Style rhs)
Combines two Style flags using bitwise OR.
constexpr bool has_style(Style styles, Style flag)
Checks if a specific style flag is set in a Style value.
std::function< std::vector< std::string >(const TextFormatter &)> FormattedMessageBuilder
Function type for building formatted messages with TextFormatter access.
constexpr Style operator&(Style lhs, Style rhs)
Masks Style flags using bitwise AND.
constexpr Style & operator&=(Style &lhs, Style rhs)
Masks an existing Style value using bitwise AND.