From: Vsevolod Stakhov Date: Wed, 8 Jun 2022 21:57:57 +0000 (+0100) Subject: [Minor] More colours X-Git-Tag: 3.3~200 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=446166742d02e94fc42f2aba2e118a499c383e63;p=thirdparty%2Frspamd.git [Minor] More colours --- diff --git a/src/client/rspamc.cxx b/src/client/rspamc.cxx index 57b57e6fa1..4163cb3486 100644 --- a/src/client/rspamc.cxx +++ b/src/client/rspamc.cxx @@ -879,15 +879,44 @@ 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"); } } @@ -895,9 +924,9 @@ rspamc_metric_output(FILE *out, const ucl_object_t *obj) 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");