]> granicus.if.org Git - procps-ng/commitdiff
top: new #define added for focus ('F') toggle tweaking
authorJim Warner <james.warner@comcast.net>
Wed, 28 Jul 2021 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Sun, 1 Aug 2021 10:39:46 +0000 (20:39 +1000)
Just to see if I could, the new #define will force the
indentation of a parent task to be reset to zero while
maintaining the proper child indentation relationship.

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

index 9a6062bf89591001ffc2ee30f7397e8c96938d53..f5125f76979b26715b2048bda7857a4f9b6a4f6b 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -4895,21 +4895,28 @@ static inline const char *forest_display (const WIN_t *q, int idx) {
 #endif
    const proc_t *p = q->ppt[idx];
    const char *which = (CHKw(q, Show_CMDLIN)) ? *p->cmdline : p->cmd;
+   int level = p->pad_3;
 
-   if (!CHKw(q, Show_FOREST) || !p->pad_3) return which;
+#ifdef TREE_FOCUS_X
+   if (q->focus_pid) {
+      if (idx >= q->focus_beg && idx < q->focus_end)
+         level -= q->focus_lvl;
+   }
+#endif
+   if (!CHKw(q, Show_FOREST) || !level) return which;
 #ifndef TREE_VWINALL
    if (q == Curwin)            // note: the following is NOT indented
 #endif
    if (p->pad_2 == 'x') {
 #ifdef TREE_VALTMRK
-      snprintf(buf, sizeof(buf), "%*s%s", (4 * p->pad_3), "`+ ", which);
+      snprintf(buf, sizeof(buf), "%*s%s", (4 * level), "`+ ", which);
 #else
-      snprintf(buf, sizeof(buf), "+%*s%s", ((4 * p->pad_3) - 1), "`- ", which);
+      snprintf(buf, sizeof(buf), "+%*s%s", ((4 * level) - 1), "`- ", which);
 #endif
       return buf;
    }
-   if (p->pad_3 > 100) snprintf(buf, sizeof(buf), "%400s%s", " +  ", which);
-   else snprintf(buf, sizeof(buf), "%*s%s", (4 * p->pad_3), " `- ", which);
+   if (level > 100) snprintf(buf, sizeof(buf), "%400s%s", " +  ", which);
+   else snprintf(buf, sizeof(buf), "%*s%s", (4 * level), " `- ", which);
    return buf;
 } // end: forest_display
 
@@ -4931,6 +4938,9 @@ static void forest_excluded (WIN_t *q) {
    if (i == Frame_maxtask)
       q->focus_pid = q->begtask = 0;
    else {
+#ifdef TREE_FOCUS_X
+      q->focus_lvl = level;
+#endif
       while (i+1 < Frame_maxtask && q->ppt[i+1]->pad_3 > level)
          ++i;
       q->focus_end = i + 1;  // make 'focus_end' a proper fencpost
index 434b9499ee222a76c340fba23bc5d482153ca4b7..90b162baa28f2db66683bbe8b9e62b25d40e2037 100644 (file)
--- a/top/top.h
+++ b/top/top.h
@@ -56,6 +56,7 @@
 //#define TERMIOS_ONLY            /* just limp along with native input only  */
 //#define TOG4_NOFORCE            /* no force 2 abreast mode with '4' toggle */
 //#define TOG4_NOTRUNC            /* ensure no truncation in 2 abreast mode  */
+//#define TREE_FOCUS_X            /* 'F' resets forest view indentation to 0 */
 //#define TREE_NORESET            /* sort keys do NOT force forest view OFF  */
 //#define TREE_SCANALL            /* rescan array w/ forest view, avoid sort */
 //#define TREE_VALTMRK            /* use an indented '+' with collapsed pids */
@@ -441,6 +442,9 @@ typedef struct WIN_t {
    int    focus_pid;                   // target pid when 'F' toggle is active
    int    focus_beg;                   // ppt index where 'F' toggle has begun
    int    focus_end;                   // ppt index where 'F' toggle has ended
+#ifdef TREE_FOCUS_X
+   int    focus_lvl;                   // the indentation level of parent task
+#endif
    proc_t **ppt;                       // this window's proc_t ptr array
    struct WIN_t *next,                 // next window in window stack
                 *prev;                 // prior window in window stack