summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Warner <james.warner@comcast.net>2022-09-12 00:00:00 -0500
committerCraig Small <csmall@dropbear.xyz>2022-09-13 20:08:22 +1000
commitf07eea2898fa124abc70e103db35e50aa67fbcf8 (patch)
treea81578d64f8a6a059d95c5d468d10f05ddf91f5f
parent737e6f5b594c07f4ab9d6b50df5ff80abf2863f2 (diff)
downloadprocps-ng-f07eea2898fa124abc70e103db35e50aa67fbcf8.tar.gz
top: better graphic scaling in cpu/mem summary display <=== port of newlib 8c69e66a
______________________________ original newlib message This program has always been sensitive to the width of a terminal/console. The detailed cpu/memory statistics plus all of those full screen replacement windows were designed to fit within some 80 column, 24 row display. When a user narrowed a gui terminal to less than those dimensions, top would simply truncate the data to fit. However, when displaying cpu/mem graphs instead of the detailed statistics such truncation was not justified. After all, such graphs were already scaled to 80 cols. Henceforth, when in graph mode, truncation won't occur until the graphs will no longer fit within 10 columns. [ can you keep a secret? this change is really being ] [ made in anticipation of showing more than just two ] [ cpu graphs in the summary area on each screen row! ] Signed-off-by: Jim Warner <james.warner@comcast.net>
-rw-r--r--top/top.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/top/top.c b/top/top.c
index 28d4aae..d7431c1 100644
--- a/top/top.c
+++ b/top/top.c
@@ -253,8 +253,10 @@ static int Numa_node_sel = -1;
/* Support for Graphing of the View_STATES ('t') and View_MEMORY ('m')
commands -- which are now both 4-way toggles */
+
#define GRAPH_prefix 25 // beginning text + opening '['
#define GRAPH_actual 100 // the actual bars or blocks
+#define GRAPH_minlen 10 // the actual bars or blocks
#define GRAPH_suffix 2 // ending ']' + trailing space
static float Graph_adj; // bars/blocks scaling factor
static int Graph_len; // scaled length (<= GRAPH_actual)
@@ -2137,16 +2139,16 @@ static void adj_geometry (void) {
PSU_CLREOS(0);
// prepare to customize potential cpu/memory graphs
- Graph_len = Screen_cols - GRAPH_prefix - GRAPH_actual - GRAPH_suffix;
- if (Graph_len >= 0) Graph_len = GRAPH_actual;
- else if (Screen_cols > 80) Graph_len = Screen_cols - GRAPH_prefix - GRAPH_suffix;
- else Graph_len = 80 - GRAPH_prefix - GRAPH_suffix;
- if (Screen_cols < DOUBLE_limit) Curwin->rc.double_up = 0;
if (Curwin->rc.double_up) {
Graph_len = (Screen_cols - DOUBLE_space - (2 * (GRAPH_prefix + GRAPH_suffix))) / 2;
Graph_len += (Screen_cols % 2) ? 0 : 1;
- if (Graph_len > GRAPH_actual) Graph_len = GRAPH_actual;
+ } else {
+ Graph_len = Screen_cols - (GRAPH_prefix + GRAPH_actual + GRAPH_suffix);
+ if (Graph_len >= 0) Graph_len = GRAPH_actual;
+ else Graph_len = Screen_cols - GRAPH_prefix - GRAPH_suffix;
}
+ if (Graph_len < GRAPH_minlen) Graph_len = GRAPH_minlen;
+ if (Graph_len > GRAPH_actual) Graph_len = GRAPH_actual;
Graph_adj = (float)Graph_len / 100.0;
fflush(stdout);
@@ -5837,10 +5839,7 @@ static void keys_summary (int ch) {
break;
case '4':
w->rc.double_up = !w->rc.double_up;
- if (w->rc.double_up && Screen_cols < DOUBLE_limit)
- w->rc.double_up = 0;
- if (w->rc.double_up)
- OFFw(w, (View_CPUSUM | View_CPUNOD));
+ OFFw(w, (View_CPUSUM | View_CPUNOD));
break;
case 'C':
VIZTOGw(w, View_SCROLL);