Skip to content

Commit

Permalink
[Minor] More colours
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Jun 8, 2022
1 parent 8480869 commit 4461667
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions src/client/rspamc.cxx
Expand Up @@ -879,25 +879,54 @@ rspamc_metric_output(FILE *out, const ucl_object_t *obj)
got_scores++;
}

print_protocol_string("action", "Action");

elt = ucl_object_lookup(obj, "action");
if (elt) {
auto act = rspamd_action_from_str_rspamc(ucl_object_tostring(elt));

if (act.has_value()) {
fmt::print(out, "Spam: {}\n", act.value() < METRIC_ACTION_GREYLIST ?
"true" : "false");
if (!tty) {
print_protocol_string("action", "Action");
}
else {
/* Colorize action type */
std::string colorized_action;
switch (act.value()) {
case METRIC_ACTION_REJECT:
colorized_action = fmt::format(fmt::fg(fmt::color::red), "reject");
break;
case METRIC_ACTION_NOACTION:
colorized_action = fmt::format(fmt::fg(fmt::color::green), "no action");
break;
case METRIC_ACTION_ADD_HEADER:
case METRIC_ACTION_REWRITE_SUBJECT:
colorized_action = fmt::format(fmt::fg(fmt::color::orange), ucl_object_tostring(elt));
break;
case METRIC_ACTION_GREYLIST:
case METRIC_ACTION_SOFT_REJECT:
colorized_action = fmt::format(fmt::fg(fmt::color::gray), ucl_object_tostring(elt));
break;
default:
colorized_action = fmt::format(fmt::emphasis::bold, ucl_object_tostring(elt));
break;
}
fmt::print(out, "Action: {}\n", colorized_action);
}

fmt::print(out, "Spam: {}\n", emphasis_argument(act.value() < METRIC_ACTION_GREYLIST ?
"true" : "false"));
}
else {
print_protocol_string("action", "Action");
}
}

print_protocol_string("subject", "Subject");

if (got_scores == 2) {
fmt::print(out,
"Score: {:.2} / {:.2}\n",
score,
required_score);
"Score: {} / {}\n",
emphasis_argument(score, "{:.2}"),
emphasis_argument(required_score, "{:.2}"));
}

elt = ucl_object_lookup(obj, "symbols");
Expand Down

0 comments on commit 4461667

Please sign in to comment.