14 auto it = theme.find(name);
21 auto pos = raw.find(
':');
23 if (pos == std::string::npos) {
26 p.
key = raw.substr(0, pos);
27 std::string style_name = raw.substr(pos + 1);
29 p.
style = resolve_style(style_name, theme);
36 static std::string
render(
const std::string& tpl,
const json& ctx, std::shared_ptr<IFormatter> formatter) {
38 result.reserve(tpl.size());
41 while (pos < tpl.size()) {
42 size_t start = tpl.find(
'{', pos);
44 if (start == std::string::npos) {
45 result.append(tpl, pos, tpl.size() - pos);
49 result.append(tpl, pos, start - pos);
51 size_t end = tpl.find(
'}', start);
52 if (end == std::string::npos) {
53 result.append(tpl, start, tpl.size() - start);
57 std::string raw = tpl.substr(start + 1, end - start - 1);
58 auto ph = parse_placeholder(raw, formatter->style());
62 if (ctx.contains(ph.key)) {
63 const auto& v = ctx[ph.key];
64 value = v.is_string() ? v.get<std::string>() : v.dump();
66 value =
"{" + ph.key +
"}";
69 result.append(formatter->colorize(value, ph.style));
std::unordered_map< std::string, Utils::COLOR > StyleMap
static std::string render(const std::string &tpl, const json &ctx, std::shared_ptr< IFormatter > formatter)
COLOR
Enumeration of available colors for formatted messages.
Defines utility functions used across all files.