From: Jim Warner Date: Sat, 30 Jun 2012 05:00:22 +0000 (-0500) Subject: top: improve scroll coordinates message handling X-Git-Tag: v3.3.4~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fbfaa868babb0974c799d45e208619412afbdfef;p=procps-ng top: improve scroll coordinates message handling With the introduction of intra-column scrolling, the scroll coordinates message was enhanced to give some hint of positioning within a scrolled column. Rather than rebuild this somewhat costly string from scratch with each frame, we'll now do the bulk of the work only when column headers are constructed. The only remaining per frame costs will then be the addition of a few terminfo escapes and the current Frame_maxtask count. Signed-off-by: Jim Warner --- diff --git a/top/top.c b/top/top.c index 1f2ab2b3..1783ab38 100644 --- a/top/top.c +++ b/top/top.c @@ -102,6 +102,10 @@ static int Screen_cols, Screen_rows, Max_lines; stick the cursor between frames. */ static int Msg_row; + /* The nearly complete scroll coordinates message for the current + window, built at the time column headers are constructed */ +static char Scroll_fmts [SMLBUFSIZ]; + /* Global/Non-windows mode stuff that is NOT persistent */ static int No_ksyms = -1, // set to '0' if ksym avail, '1' otherwise PSDBopen = 0, // set to '1' if psdb opened (now postponed) @@ -680,30 +684,9 @@ static int show_pmt (const char *str) { * Show a special coordinate message, in support of scrolling */ static inline void show_scroll (void) { char tmp[SMLBUFSIZ]; -#ifndef SCROLLVAR_NO - char tmp2[SMLBUFSIZ]; -#endif - int totpflgs = Curwin->totpflgs; - int begpflgs = Curwin->begpflg + 1; -#ifndef USE_X_COLHDR - if (CHKw(Curwin, Show_HICOLS)) { - totpflgs -= 2; - if (ENUpos(Curwin, Curwin->rc.sortindx) < Curwin->begpflg) begpflgs -= 2; - } -#endif - if (1 > totpflgs) totpflgs = 1; - if (1 > begpflgs) begpflgs = 1; - snprintf(tmp, sizeof(tmp) - , N_fmt(SCROLL_coord_fmt) - , Curwin->begtask + 1, Frame_maxtask - , begpflgs, totpflgs); -#ifndef SCROLLVAR_NO - snprintf(tmp2, sizeof(tmp2), Curwin->varcolbeg ? " + %d" : "", Curwin->varcolbeg); - PUTT("%s%s %.*s%s%s", tg2(0, Msg_row), Caps_off, Screen_cols - 2, tmp, tmp2, Cap_clr_eol); -#else + snprintf(tmp, sizeof(tmp), Scroll_fmts, Frame_maxtask); PUTT("%s%s %.*s%s", tg2(0, Msg_row), Caps_off, Screen_cols - 2, tmp, Cap_clr_eol); -#endif putp(tg2(0, Msg_row)); } // end: show_scroll @@ -796,6 +779,35 @@ static void show_special (int interact, const char *glob) { 'fit-to-screen' thingy while also leaving room for the cursor... */ if (*glob) PUTT("%.*s", Screen_cols -1, glob); } // end: show_special + + + /* + * Create a nearly complete scroll coordinates message, but still + * technically a format string since we're missing total tasks. */ +static void updt_scroll_msg (void) { +#ifndef SCROLLVAR_NO + char tmp[SMLBUFSIZ]; +#endif + int totpflgs = Curwin->totpflgs; + int begpflgs = Curwin->begpflg + 1; + +#ifndef USE_X_COLHDR + if (CHKw(Curwin, Show_HICOLS)) { + totpflgs -= 2; + if (ENUpos(Curwin, Curwin->rc.sortindx) < Curwin->begpflg) begpflgs -= 2; + } +#endif + if (1 > totpflgs) totpflgs = 1; + if (1 > begpflgs) begpflgs = 1; + snprintf(Scroll_fmts, sizeof(Scroll_fmts) + , N_fmt(SCROLL_coord_fmt) + , Curwin->begtask + 1 + , begpflgs, totpflgs); +#ifndef SCROLLVAR_NO + snprintf(tmp, sizeof(tmp), Curwin->varcolbeg ? " + %d" : "", Curwin->varcolbeg); + scat (Scroll_fmts, tmp); +#endif +} // end: updt_scroll_msg /*###### Low Level Memory/Keyboard support #############################*/ @@ -1552,6 +1564,8 @@ static void calibrate_fields (void) { } while (w != Curwin); build_headers(); + if (CHKw(Curwin, View_SCROLL)) + updt_scroll_msg(); Frames_resize = 0; if (-1 == sigprocmask(SIG_SETMASK, &oldss, NULL)) diff --git a/top/top.h b/top/top.h index 588f3bb3..70072d5c 100644 --- a/top/top.h +++ b/top/top.h @@ -588,6 +588,7 @@ typedef struct WIN_t { //atic int show_pmt (const char *str); //atic inline void show_scroll (void); //atic void show_special (int interact, const char *glob); +//atic void updt_scroll_msg (void); /*------ Low Level Memory/Keyboard support -----------------------------*/ //atic void *alloc_c (size_t num); //atic void *alloc_r (void *ptr, size_t num); diff --git a/top/top_nls.c b/top/top_nls.c index e31d4c4a..b533674d 100644 --- a/top/top_nls.c +++ b/top/top_nls.c @@ -221,7 +221,7 @@ static void build_norm_nlstab (void) { Norm_nlstab[HILIGHT_cant_txt] = _("Nothing to highlight!"); Norm_nlstab[GET_user_ids_txt] = _("Which user (blank for all)"); Norm_nlstab[UNKNOWN_cmds_txt] = _("Unknown command - try 'h' for help"); - Norm_nlstab[SCROLL_coord_fmt] = _("scroll coordinates: y = %d/%d (tasks), x = %d/%d (fields)"); + Norm_nlstab[SCROLL_coord_fmt] = _("scroll coordinates: y = %d/%%d (tasks), x = %d/%d (fields)"); Norm_nlstab[FAIL_alloc_c_txt] = _("failed memory allocate"); Norm_nlstab[FAIL_alloc_r_txt] = _("failed memory re-allocate"); Norm_nlstab[BAD_numfloat_txt] = _("Unacceptable floating point");