6#define DEFINE_COLOR_HELPER(name) \
7inline std::string name(const std::string& text) { \
8 auto fmt = FormatterManager::get_formatter(); \
9 return fmt->colorize(text, Utils::name); \
16 formatter() = std::move(f);
22 static auto fallback =
23 std::make_shared<ConsoleFormatter>();
34 return current_format();
39 const std::string& template_str,
40 const std::vector<T>& data,
43 std::ostream& out = std::cout
46 effective = current_format();
49 if (effective != current_format()) {
53 json arr = json::array();
55 for (
const auto& x : data) arr.push_back(x);
56 out << arr.dump(2) <<
"\n";
62 for (
const auto& item : data) {
65 if (color_fn && formatter) {
66 line = formatter->colorize(line, color_fn(i));
72 if (data.size() <= 0) {
73 out << template_str <<
"\n";
79 const std::string& template_str,
83 std::ostream& out = std::cout
85 write<T>(template_str, std::vector<T>{item}, effective, color_fn, out);
88 static void write(
const std::string& str, std::ostream& out = std::cout) {
92 static void warn(
const std::string& str) {
98 std::string warning = fmt->colorize(
"Warning: ", bold);
99 warning = fmt->colorize(warning, warn_color);
101 write(warning + str, std::cerr);
105 static std::shared_ptr<IFormatter>& formatter() {
106 static std::shared_ptr<IFormatter> f =
107 std::make_shared<ConsoleFormatter>();
111 static Format& current_format() {
std::function< Utils::COLOR(size_t)> RowColorFn
static std::string render(const std::string &tpl, const json &ctx, std::shared_ptr< IFormatter > formatter)
COLOR
Enumeration of available colors for formatted messages.