]> granicus.if.org Git - procps-ng/commitdiff
top: enhanced 'scale_tics' function for Ctrl-E scaling
authorJim Warner <james.warner@comcast.net>
Sun, 6 Mar 2022 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@dropbear.xyz>
Mon, 7 Mar 2022 09:29:06 +0000 (20:29 +1100)
When scale_tics was refactored and then Ctrl-E support
added to top, the complete range of scaling values was
not visible. Namely, a single 'd' (days) & 'w' (weeks)
was never seen with ^E. With this commit they will be.

Reference(s):
. Mar, 2022 - introduced ^E tics scaling
commit 402bf1903b25ac78b0c4cbf63d457feee78a391c
. Mar, 2022 - refactored scale_tics
commit 71eb90c1b27ef039ccc90f6060406099df45eade

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

index d703b279b8a76fe1d0aa9422e0ff225c83720426..09a4b9f4cfe0722275d68a06b09242c400862a5c 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -1633,8 +1633,10 @@ end_justifies:
 #define TICS_AS_SECS  0
 #define TICS_AS_MINS  1
 #define TICS_AS_HOUR  2
-#define TICS_AS_DAYS  3
-#define TICS_AS_WEEK  4
+#define TICS_AS_DAY1  3
+#define TICS_AS_DAY2  4
+#define TICS_AS_WEEK  5
+#define TICS_AS_LAST  6
 
         /*
          * Do some scaling stuff.
@@ -1719,7 +1721,7 @@ static const char *scale_tics (TIC_t tics, int width, int justr, int target) {
             if (width >= snprintf(buf, sizeof(buf), "%lu,%02lu", hour, mins % 60))
                goto end_justifies;
          }
-      case TICS_AS_DAYS:                        // fall through
+      case TICS_AS_DAY1:                        // fall through
          if (days < ddLIMIT + 1) {
             if (width >= snprintf(buf, sizeof(buf), DD "+" HH, days, hour % 24))
                goto end_justifies;
@@ -1727,6 +1729,7 @@ static const char *scale_tics (TIC_t tics, int width, int justr, int target) {
             if (width >= snprintf(buf, sizeof(buf), DD "+%lu", days, hour % 24))
                goto end_justifies;
 #endif
+      case TICS_AS_DAY2:                        // fall through
             if (width >= snprintf(buf, sizeof(buf), DD, days))
                goto end_justifies;
          }
@@ -1737,6 +1740,7 @@ static const char *scale_tics (TIC_t tics, int width, int justr, int target) {
          if (width >= snprintf(buf, sizeof(buf), WW "+%lu", week, days % 7))
             goto end_justifies;
 #endif
+      case TICS_AS_LAST:                        // fall through
          if (width >= snprintf(buf, sizeof(buf), WW, week))
             goto end_justifies;
       default:                                  // fall through
@@ -3884,7 +3888,7 @@ static const char *configs_file (FILE *fp, const char *name, float *delay) {
       Rc.task_mscale = 0;
    if (Rc.zero_suppress < 0 || Rc.zero_suppress > 1)
       Rc.zero_suppress = 0;
-   if (Rc.tics_scaled < 0 || Rc.tics_scaled > TICS_AS_WEEK)
+   if (Rc.tics_scaled < 0 || Rc.tics_scaled > TICS_AS_LAST)
       Rc.tics_scaled = 0;
 
    // prepare to warn that older top can no longer read rcfile ...
@@ -5156,7 +5160,7 @@ static void keys_global (int ch) {
       case kbd_CtrlE:
 #ifndef SCALE_FORMER
          Rc.tics_scaled++;
-         if (Rc.tics_scaled > TICS_AS_WEEK)
+         if (Rc.tics_scaled > TICS_AS_LAST)
             Rc.tics_scaled = 0;
 #endif
          break;