commit f80438c: [Minor] Add some terminal stuff

Vsevolod Stakhov vsevolod at rspamd.com
Tue Jun 7 21:14:05 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-06-07 19:50:52 +0100
URL: https://github.com/rspamd/rspamd/commit/f80438cc46f214c2716d0f5fc47370baa487a5af

[Minor] Add some terminal stuff

---
 src/client/rspamc.cxx      | 28 ++++++++++++++++------------
 src/libstat/CMakeLists.txt |  1 +
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/client/rspamc.cxx b/src/client/rspamc.cxx
index eb82b0208..283e8d2a1 100644
--- a/src/client/rspamc.cxx
+++ b/src/client/rspamc.cxx
@@ -751,7 +751,8 @@ rspamc_metric_output(FILE *out, const ucl_object_t *obj)
 	auto print_protocol_string = [&](const char *ucl_name, const char *output_message) {
 		auto *elt = ucl_object_lookup(obj, ucl_name);
 		if (elt) {
-			fmt::print(out, "{}: {}\n", output_message, ucl_object_tostring(elt));
+			fmt::print(out, "{}: {}\n", output_message,
+					fmt::format(fmt::emphasis::bold, "{}", ucl_object_tostring(elt)));
 		}
 	};
 
@@ -1115,17 +1116,19 @@ rspamc_stat_actions(ucl_object_t *obj, std::string &out, std::int64_t scanned)
 		if (actions && ucl_object_type(actions) == UCL_OBJECT) {
 			while ((cur = ucl_object_iterate (actions, &iter, true)) != nullptr) {
 				auto cnt = ucl_object_toint(cur);
-				fmt::format_to(std::back_inserter(out), "Messages with action {}: {}, {:.2f}%",
-						ucl_object_key(cur), cnt,
+				fmt::format_to(std::back_inserter(out), "Messages with action {}: {}, {:.2f}%\n",
+						ucl_object_key(cur), fmt::format(fmt::emphasis::bold, "{}", cnt),
 						((double) cnt / (double) scanned) * 100.);
 			}
 		}
 
 		auto spam = ucl_object_toint(ucl_object_lookup(obj, "spam_count"));
 		auto ham = ucl_object_toint(ucl_object_lookup(obj, "ham_count"));
-		fmt::format_to(std::back_inserter(out), "Messages treated as spam: {}, {:.2f}%\n", spam,
+		fmt::format_to(std::back_inserter(out), "Messages treated as spam: {}, {:.2f}%\n",
+				fmt::format(fmt::emphasis::bold, "{}", ham),
 				((double) spam / (double) scanned) * 100.);
-		fmt::format_to(std::back_inserter(out), "Messages treated as ham: {}, {:.2f}%\n", ham,
+		fmt::format_to(std::back_inserter(out), "Messages treated as ham: {}, {:.2f}%\n",
+					   fmt::format(fmt::emphasis::bold, "{}", ham),
 				((double) ham / (double) scanned) * 100.);
 	}
 }
@@ -1167,16 +1170,17 @@ rspamc_stat_output(FILE *out, ucl_object_t *obj)
 	out_str.reserve(8192);
 
 	auto scanned = ucl_object_toint(ucl_object_lookup(obj, "scanned"));
-	fmt::format_to(std::back_inserter(out_str), "Messages scanned: {}\n", scanned);
+	fmt::format_to(std::back_inserter(out_str), "Messages scanned: {}\n",
+				   fmt::format(fmt::emphasis::bold, "{}", scanned));
 
 	rspamc_stat_actions(obj, out_str, scanned);
 
 	fmt::format_to(std::back_inserter(out_str), "Messages learned: {}\n",
-			ucl_object_toint(ucl_object_lookup(obj, "learned")));
+			fmt::format(fmt::emphasis::bold, "{}", ucl_object_toint(ucl_object_lookup(obj, "learned"))));
 	fmt::format_to(std::back_inserter(out_str), "Connections count: {}\n",
-			ucl_object_toint(ucl_object_lookup(obj, "connections")));
+			fmt::format(fmt::emphasis::bold, "{}",ucl_object_toint(ucl_object_lookup(obj, "connections"))));
 	fmt::format_to(std::back_inserter(out_str), "Control connections count: {}\n",
-			ucl_object_toint(ucl_object_lookup(obj, "control_connections")));
+			fmt::format(fmt::emphasis::bold, "{}",ucl_object_toint(ucl_object_lookup(obj, "control_connections"))));
 
 	const auto *avg_time_obj = ucl_object_lookup(obj, "scan_times");
 
@@ -1196,7 +1200,7 @@ rspamc_stat_output(FILE *out, ucl_object_t *obj)
 		if (cnt > 0) {
 			auto sum = rspamd_sum_floats(nums.data(), &cnt);
 			fmt::format_to(std::back_inserter(out_str),
-						   "Average scan time: {:.3f} sec\n", sum / cnt);
+						   "Average scan time: {} sec\n", fmt::format(fmt::emphasis::bold, "{:.3f}", sum / cnt));
 		}
 	}
 
@@ -1562,13 +1566,13 @@ rspamc_client_cb(struct rspamd_client_connection *conn,
 			if (cmd.need_input && !json) {
 				if (!compact) {
 					fmt::print(out, "Results for file: {} ({:.3} seconds)\n",
-							cbdata->filename, diff);
+							fmt::format(fmt::emphasis::bold, "{}", cbdata->filename), diff);
 				}
 			}
 			else {
 				if (!compact && !json) {
 					fmt::print(out, "Results for command: {} ({:.3} seconds)\n",
-							cmd.name, diff);
+							fmt::format(fmt::emphasis::bold, "{}", cmd.name), diff);
 				}
 			}
 
diff --git a/src/libstat/CMakeLists.txt b/src/libstat/CMakeLists.txt
index 19962239d..b1df5c1e6 100644
--- a/src/libstat/CMakeLists.txt
+++ b/src/libstat/CMakeLists.txt
@@ -11,6 +11,7 @@ SET(CLASSIFIERSSRC	${CMAKE_CURRENT_SOURCE_DIR}/classifiers/bayes.c
 SET(BACKENDSSRC 	${CMAKE_CURRENT_SOURCE_DIR}/backends/mmaped_file.c
 					${CMAKE_CURRENT_SOURCE_DIR}/backends/sqlite3_backend.c
 					${CMAKE_CURRENT_SOURCE_DIR}/backends/cdb_backend.cxx
+					${CMAKE_CURRENT_SOURCE_DIR}/backends/http_backend.cxx
 					${CMAKE_CURRENT_SOURCE_DIR}/backends/redis_backend.c)
 
 SET(CACHESSRC 	${CMAKE_CURRENT_SOURCE_DIR}/learn_cache/sqlite3_cache.c


More information about the Commits mailing list