From 6f25f956e77356ee01a3b63c6c863b5f6d2dffbc Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Tue, 29 Jan 2013 00:00:00 -0600 Subject: [PATCH] top: a few small adjustments to reduce display flicker This change involves the Fields Management logic only. With user position being maintained after signals, the previous algorithm unfortunately used Cap_clr_eos with each iteration of the loop. The screen flicker invited with that choice was not apparent under all emulators. With this commit, clearing to end-of-screen has become conditional on whether or not there was a true resize. (everything is perfectly justified plus right margins) (are completely filled, but of course it must be luck) Reference(s): commit ba9092ad83d37d9eb91ded49380a9bedeba4bac6 Signed-off-by: Jim Warner --- top/top.c | 17 ++++++++++++----- top/top_nls.c | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/top/top.c b/top/top.c index 5987194f..92f5a3f9 100644 --- a/top/top.c +++ b/top/top.c @@ -1841,6 +1841,7 @@ static void display_fields (int focus, int extend) { int xadd = 0; // spacing between data columns int cmax = Screen_cols; // total data column width int rmax = Screen_rows - yRSVD; // total useable rows + static int col_sav, row_sav; i = (P_MAXPFLGS % mxCOL) ? 1 : 0; if (rmax < i + (P_MAXPFLGS / mxCOL)) error_exit("++rows"); // nls_maybe @@ -1851,6 +1852,15 @@ static void display_fields (int focus, int extend) { smax = cmax - xPRFX; if (smax < 0) error_exit("++cols"); // nls_maybe + /* we'll go the extra distance to avoid any potential screen flicker + which occurs under some terminal emulators (but it was our fault) */ + if (col_sav != Screen_cols || row_sav != Screen_rows) { + col_sav = Screen_cols; + row_sav = Screen_rows; + putp(Cap_clr_eos); + } + fflush(stdout); + for (i = 0; i < P_MAXPFLGS; ++i) { int b = FLDviz(w, i), x = (i / rmax) * cmax, y = (i % rmax) + yRSVD; const char *e = (i == focus && extend) ? w->capclr_hdr : ""; @@ -1860,7 +1870,7 @@ static void display_fields (int focus, int extend) { // prep sacrificial suffix snprintf(sbuf, sizeof(sbuf), "= %s", N_fld(f)); - PUTT("%s%c%s%s %s%-7.7s%s%s%s %-*.*s%s%s" + PUTT("%s%c%s%s %s%-7.7s%s%s%s %-*.*s%s" , tg2(x, y) , b ? '*' : ' ' , b ? w->cap_bold : Cap_norm @@ -1872,8 +1882,7 @@ static void display_fields (int focus, int extend) { , e , smax, smax , sbuf - , Cap_norm - , !x ? Cap_clr_eol : ""); + , Cap_norm); } putp(Caps_off); @@ -1915,8 +1924,6 @@ signify_that: putp(Cap_home); show_special(1, fmtmk(N_unq(FIELD_header_fmt) , w->grpname, CHKw(w, Show_FOREST) ? N_txt(FOREST_views_txt) : h)); - putp(Cap_nl_clreos); - fflush(stdout); display_fields(i, (p != NULL)); fflush(stdout); diff --git a/top/top_nls.c b/top/top_nls.c index 244fc53a..44377931 100644 --- a/top/top_nls.c +++ b/top/top_nls.c @@ -568,7 +568,7 @@ static void build_uniq_nlstab (void) { Uniq_nlstab[FIELD_header_fmt] = _("" "Fields Management~2 for window ~1%s~6, whose current sort field is ~1%s~2\n" " Navigate with Up/Dn, Right selects for move then or Left commits,\n" - " 'd' or toggles display, 's' sets sort. Use 'q' or to end! "); + " 'd' or toggles display, 's' sets sort. Use 'q' or to end!\n"); Uniq_nlstab[STATE_line_1_fmt] = _("%s:~3" " %3u ~2total,~3 %3u ~2running,~3 %3u ~2sleeping,~3 %3u ~2stopped,~3 %3u ~2zombie~3\n");