Hide the indicator while printing info messages

This commit is contained in:
Přemysl Eric Janouch 2015-06-27 22:07:52 +02:00
parent de4009fb4d
commit 871ae9be8e
1 changed files with 24 additions and 3 deletions

View File

@ -413,9 +413,6 @@ app_context_free (struct app_context *self)
// --- Progress indicator ------------------------------------------------------ // --- 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 static void
indicator_set_timer (struct indicator *self) indicator_set_timer (struct indicator *self)
{ {
@ -1749,6 +1746,26 @@ setup_signal_handlers (void)
exit_fatal ("sigaction: %s", strerror (errno)); 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 ------------------------------------------------------------ // --- Main program ------------------------------------------------------------
typedef bool (*list_foreach_fn) (void *, const char *); typedef bool (*list_foreach_fn) (void *, const char *);
@ -2158,6 +2175,10 @@ main (int argc, char *argv[])
merge_port_ranges (&ctx); merge_port_ranges (&ctx);
merge_ip_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 // Initate the scan: generate as many units as possible
generator_init (&ctx); generator_init (&ctx);
while (generator_step (&ctx)) while (generator_step (&ctx))