summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Warner <james.warner@comcast.net>2022-09-09 00:00:00 -0500
committerCraig Small <csmall@dropbear.xyz>2022-09-12 22:15:28 +1000
commit8c69e66a1a1bfa472c5aec9b9ef7cd445690bd04 (patch)
treed0e3c42bb93c485c77bb8060c9534b834d85e252 /src
parent2d5b51d1a2aa19d077a2f3db5be187f982d70e70 (diff)
downloadprocps-ng-8c69e66a1a1bfa472c5aec9b9ef7cd445690bd04.tar.gz
top: better graphic scaling in cpu/mem summary display
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>
Diffstat (limited to 'src')
-rw-r--r--src/top/top.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/top/top.c b/src/top/top.c
index a975ec9..3308d10 100644
--- a/src/top/top.c
+++ b/src/top/top.c
@@ -224,8 +224,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)
@@ -2068,16 +2070,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);
@@ -5704,10 +5706,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);