From 688f4e7399f6810f8ef67a344c14bff649a153f5 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sat, 15 Dec 2012 00:00:00 -0600 Subject: [PATCH] top: add the ability to suppress zeros in most columns With the increased width and precision of memory and % columns, the proliferation of 0's when there's nothing to report seems like a distraction versus useful data. This commit introduces the '0' toggle which can either display or suppress those zeros. And, like the scaling states this new state is also preserved in the rcfile. (now that we know a '.' + 2 spaces is squeezed to one) (everything's perfectly justified, but it's just luck) Signed-off-by: Jim Warner --- top/top.1 | 8 +++++++- top/top.c | 13 ++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/top/top.1 b/top/top.1 index e6ab28cd..c914e771 100644 --- a/top/top.1 +++ b/top/top.1 @@ -836,7 +836,7 @@ depending on the context in which they are issued. .Bd -literal 4a.\fI Global-Commands \fR - ?, =, + ?, =, 0, A, B, d, E, g, h, H, I, k, q, r, s, W, X, Y, Z 4b.\fI Summary-Area-Commands \fR C, l, t, 1, m @@ -900,6 +900,12 @@ vertical and horizontal scrolling. When operating in \*(AM this command has a broader meaning. +.TP 7 +\ \ \'\fB0\fR\' :\fIZero-Suppress\fR toggle \fR +This command determines whether zeros are shown or suppressed for many +of the fields in a \*(TW. +Fields like UID, GID, NI, PR or P are not affected by this toggle. + .TP 7 \ \ \'\fBA\fR\' :\fIAlternate-Display-Mode\fR toggle \fR This command will switch between \*(FM and \*(AM. diff --git a/top/top.c b/top/top.c index 204a6783..0dadc870 100644 --- a/top/top.c +++ b/top/top.c @@ -3113,8 +3113,8 @@ static void configs_read (void) { } // end: for (GROUPSMAX) // any new addition(s) last, for older rcfiles compatibility... - fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d\n" - , &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale); + fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n" + , &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress); try_inspect_entries: @@ -3702,8 +3702,8 @@ static void file_writerc (void) { } // any new addition(s) last, for older rcfiles compatibility... - fprintf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d\n" - , Rc.fixed_widest, Rc.summ_mscale, Rc.task_mscale); + fprintf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n" + , Rc.fixed_widest, Rc.summ_mscale, Rc.task_mscale, Rc.zero_suppress); if (Inspect.raw) fputs(Inspect.raw, fp); @@ -3901,6 +3901,9 @@ static void keys_global (int ch) { case 'Z': wins_colors(); break; + case '0': + Rc.zero_suppress = !Rc.zero_suppress; + break; case kbd_ENTER: // these two have the effect of waking us case kbd_SPACE: // from 'select()', updating hotplugged sysinfo_refresh(1); // resources and refreshing the display @@ -4364,7 +4367,7 @@ static void do_key (int ch) { } key_tab[] = { { keys_global, { '?', 'B', 'd', 'E', 'e', 'F', 'f', 'g', 'H', 'h' - , 'I', 'k', 'r', 's', 'X', 'Y', 'Z' + , 'I', 'k', 'r', 's', 'X', 'Y', 'Z', '0' , kbd_ENTER, kbd_SPACE, '\0' } }, { keys_summary, { '1', 'C', 'l', 'm', 't', '\0' } },