From 871ae9be8e064aa1a4db575f0209cc87a2c849c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sat, 27 Jun 2015 22:07:52 +0200 Subject: Hide the indicator while printing info messages --- ponymap.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/ponymap.c b/ponymap.c index 290dd21..2726675 100644 --- a/ponymap.c +++ b/ponymap.c @@ -413,9 +413,6 @@ app_context_free (struct app_context *self) // --- Progress indicator ------------------------------------------------------ -// TODO: make it so that the indicator is hidden while printing messages to -// the same terminal -> wrapper for log_message_stdio(). - static void indicator_set_timer (struct indicator *self) { @@ -1749,6 +1746,26 @@ setup_signal_handlers (void) exit_fatal ("sigaction: %s", strerror (errno)); } +// --- Logging ----------------------------------------------------------------- + +// The indicator can get in the way of printing information messages + +static struct app_context *g_ctx; ///< Application context + +static void +log_message_wrapper (void *user_data, const char *quote, const char *fmt, + va_list ap) +{ + bool hide_indicator = g_ctx->indicator.shown; + if (hide_indicator) + indicator_hide (&g_ctx->indicator); + + log_message_stdio (user_data, quote, fmt, ap); + + if (hide_indicator) + indicator_show (&g_ctx->indicator); +} + // --- Main program ------------------------------------------------------------ typedef bool (*list_foreach_fn) (void *, const char *); @@ -2158,6 +2175,10 @@ main (int argc, char *argv[]) merge_port_ranges (&ctx); merge_ip_ranges (&ctx); + // Wrap the logger so that it is synchronized with the indicator + g_ctx = &ctx; + g_log_message_real = log_message_wrapper; + // Initate the scan: generate as many units as possible generator_init (&ctx); while (generator_step (&ctx)) -- cgit v1.2.3