]> granicus.if.org Git - procps-ng/commitdiff
top: refactor the 'scroll coordinates' message support
authorJim Warner <james.warner@comcast.net>
Wed, 20 Jun 2018 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Sat, 23 Jun 2018 12:03:57 +0000 (22:03 +1000)
This patch is simply preparation for upcoming vertical
scrolling enhancements. With those changes, it will be
impossible to predict what the beginning task position
should be at the time the message is currently issued.

This patch will allow such a message to be shown after
the individual windows' tasks have all been displayed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c
top/top.h
top/top_nls.c

index 978e58b6dd848aac62cc7e7bc739459345936e3a..722ca94f18f4821ca2f0f566190064c0836ec559 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -112,10 +112,6 @@ 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 Batch = 0,           // batch mode, collect no input, dumb output
            Loops = -1,          // number of iterations, -1 loops forever
@@ -905,6 +901,32 @@ static int show_pmt (const char *str) {
 } // end: show_pmt
 
 
+        /*
+         * Create and print the optional scroll coordinates message */
+static void show_scroll (void) {
+   char tmp1[SMLBUFSIZ], tmp2[SMLBUFSIZ];
+   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(tmp1, sizeof(tmp1), N_fmt(SCROLL_coord_fmt), Curwin->begtask + 1, Frame_maxtask, begpflgs, totpflgs);
+#ifndef SCROLLVAR_NO
+   if (Curwin->varcolbeg) {
+      snprintf(tmp2, sizeof(tmp2), " + %d", Curwin->varcolbeg);
+      scat(tmp1, tmp2);
+   }
+#endif
+   PUTT("%s%s  %.*s%s", tg2(0, Msg_row), Caps_off, Screen_cols - 3, tmp1, Cap_clr_eol);
+} // end: show_scroll
+
+
         /*
          * Show lines with specially formatted elements, but only output
          * what will fit within the current screen width.
@@ -1011,36 +1033,6 @@ static void show_special (int interact, const char *glob) {
       'fit-to-screen' thingy while also leaving room for the cursor... */
    if (*glob) PUTT("%.*s", utf8_embody(glob, Screen_cols - 1), glob);
 } // end: show_special
-
-
-        /*
-         * Create a nearly complete scroll coordinates message, but still
-         * a format string since we'll be missing the current total tasks. */
-static void updt_scroll_msg (void) {
-   char tmp1[SMLBUFSIZ], tmp2[SMLBUFSIZ];
-   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(tmp1, sizeof(tmp1)
-      , N_fmt(SCROLL_coord_fmt), Curwin->begtask + 1, begpflgs, totpflgs);
-   strcpy(tmp2, tmp1);
-#ifndef SCROLLVAR_NO
-   if (Curwin->varcolbeg)
-      snprintf(tmp2, sizeof(tmp2), "%s + %d", tmp1, Curwin->varcolbeg);
-#endif
-   // this Scroll_fmts string no longer provides for termcap tgoto so that
-   // the usage timing is critical -- see frame_make() for additional info
-   snprintf(Scroll_fmts, sizeof(Scroll_fmts)
-      , "%s  %.*s%s", Caps_off, Screen_cols - 3, tmp2, Cap_clr_eol);
-} // end: updt_scroll_msg
 \f
 /*######  Low Level Memory/Keyboard/File I/O support  ####################*/
 
@@ -2148,8 +2140,6 @@ static void calibrate_fields (void) {
    } while (w != Curwin);
 
    build_headers();
-   if (CHKw(Curwin, View_SCROLL))
-      updt_scroll_msg();
 } // end: calibrate_fields
 
 
@@ -6316,12 +6306,8 @@ static void frame_make (void) {
    Max_lines = (Screen_rows - Msg_row) - 1;
    OFFw(w, INFINDS_xxx);
 
-   /* one way or another, rid us of any prior frame's msg
-      [ now that this is positioned after the call to summary_show(), ]
-      [ we no longer need or employ tg2(0, Msg_row) since all summary ]
-      [ lines end with a newline, and header lines begin with newline ] */
-   if (VIZISw(w) && CHKw(w, View_SCROLL)) PUTT(Scroll_fmts, Frame_maxtask);
-   else putp(Cap_clr_eol);
+   // we're now on Msg_row so clear out any residual messages ...
+   putp(Cap_clr_eol);
 
    if (!Rc.mode_altscr) {
       // only 1 window to show so, piece o' cake
@@ -6344,6 +6330,9 @@ static void frame_make (void) {
       putp(Cap_nl_clreos);
       PSU_CLREOS(Pseudo_row);
    }
+
+   if (CHKw(w, View_SCROLL) && VIZISw(Curwin))
+      show_scroll();
    fflush(stdout);
 
    /* we'll deem any terminal not supporting tgoto as dumb and disable
index 3ae65d58f50fadc0e30fbe6f0ebe8252de58b19a..f489e9571cf0c05e5aab51888b05751d4746c6af 100644 (file)
--- a/top/top.h
+++ b/top/top.h
@@ -696,8 +696,8 @@ typedef struct WIN_t {
 //atic void          capsmk (WIN_t *q);
 //atic void          show_msg (const char *str);
 //atic int           show_pmt (const char *str);
+//atic void          show_scroll (void);
 //atic void          show_special (int interact, const char *glob);
-//atic void          updt_scroll_msg (void);
 /*------  Low Level Memory/Keyboard/File I/O support  --------------------*/
 //atic void         *alloc_c (size_t num);
 //atic void         *alloc_r (void *ptr, size_t num);
index 828ca788b5a402bf92f7f61450b53d60d3d7d0b8..223e6ef5531e6c8a31db4027fbc0ce9e0dcc5a10 100644 (file)
@@ -377,7 +377,7 @@ static void build_norm_nlstab (void) {
    Norm_nlstab[BAD_max_task_txt] = _("Invalid maximum");
    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");