From b39b142f6b99074376fad020e65e22e42809b971 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Fri, 6 Nov 2015 00:07:45 +0200 Subject: flowtop: Redraw screen in 1s if no key was pressed Seems like screen is updating too frequently which may block some terminals, so lets do it once in 1s but only if no key was pressed. Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- flowtop.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/flowtop.c b/flowtop.c index 2791a74..d4a8ad9 100644 --- a/flowtop.c +++ b/flowtop.c @@ -1161,6 +1161,8 @@ static void presenter_screen_update(WINDOW *screen, struct flow_list *fl, static void presenter(void) { + int time_sleep_us = 200000; + int time_passed_us = 0; int skip_lines = 0; WINDOW *screen; @@ -1170,6 +1172,8 @@ static void presenter(void) rcu_register_thread(); while (!sigint) { + bool do_redraw = true; + switch (getch()) { case 'q': sigint = 1; @@ -1190,11 +1194,21 @@ static void presenter(void) break; default: fflush(stdin); + do_redraw = false; break; } - presenter_screen_update(screen, &flow_list, skip_lines); - usleep(200000); + if (!do_redraw) + do_redraw = time_passed_us >= 1 * USEC_PER_SEC; + + if (do_redraw) { + presenter_screen_update(screen, &flow_list, skip_lines); + time_passed_us = 0; + } else { + time_passed_us += time_sleep_us; + } + + usleep(time_sleep_us); } rcu_unregister_thread(); -- cgit v1.2.3-54-g00ecf