diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-27 22:07:52 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-27 22:07:52 +0200 |
commit | 871ae9be8e064aa1a4db575f0209cc87a2c849c7 (patch) | |
tree | 40d37e5ad5534f2957b922948b1b5ee8968a709a | |
parent | de4009fb4de679b2efe89e2736436060eb4a8e6d (diff) | |
download | ponymap-871ae9be8e064aa1a4db575f0209cc87a2c849c7.tar.gz ponymap-871ae9be8e064aa1a4db575f0209cc87a2c849c7.tar.xz ponymap-871ae9be8e064aa1a4db575f0209cc87a2c849c7.zip |
Hide the indicator while printing info messages
-rw-r--r-- | ponymap.c | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -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)) |