top: enhance memory graphs two abreast summary display <=== port of newlib 602146a6

______________________________ original newlib message

This patch introduces a new #define TOG4_MEM_FIX which
serves to turn off the new feature it also implements.

The feature, on by default, provides a flexible memory
graph approach which strives to always keep its visual
separator in alignment with cpu separators seen above.

Below is a summary of the algorithm implementing this:

1) First, ascertain the widest graph which corresponds
to the largest number of cpu graphs but doesn't exceed
maximum allowable graph width (i.e. GRAPH_length_max).

2) Next, apply that to the graphed 'Mem' portion which
is likely to remain entirely visible. However, it will
grow or shrink depending on total adjacent cpu graphs.

3) Last, the same width is used for the 'Swap' portion
but that graph is considered sacrificial and very well
could be truncated depending on the width of a screen.

[ along the way, when the cpu graphs revert to their ]
[ abbreviated form, the memory graphs will also show ]
[ an abbreviated prefix. in this way the widths will ]
[ also be maximized, reducing potential distortions. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2022-09-19 00:00:00 -05:00 committed by Craig Small
parent 729a25ee1c
commit 2e84fdb05b
2 changed files with 54 additions and 6 deletions

View File

@ -2152,21 +2152,46 @@ static void adj_geometry (void) {
if (Curwin->rc.double_up) {
int num = (Curwin->rc.double_up + 1);
int pfx = (Curwin->rc.double_up < 2) ? GRAPH_prefix_std : GRAPH_prefix_abv;
Graph_cpus->length = (Screen_cols - (ADJOIN_space * Curwin->rc.double_up) - (num * (pfx + GRAPH_suffix))) / num;
Graph_mems->length = (Screen_cols - ADJOIN_space - (2 * (GRAPH_prefix_std + GRAPH_suffix))) / 2;
if (Graph_cpus->length > GRAPH_length_max) Graph_cpus->length = GRAPH_length_max;
if (Graph_cpus->length < GRAPH_length_min) Graph_cpus->length = GRAPH_length_min;
Graph_mems->length = (Screen_cols - ADJOIN_space - (2 * (pfx + GRAPH_suffix))) / 2;
if (Graph_mems->length > GRAPH_length_max) Graph_mems->length = GRAPH_length_max;
if (Graph_mems->length < GRAPH_length_min) Graph_mems->length = GRAPH_length_min;
#if !defined(TOG4_MEM_FIX) && !defined(TOG4_MEM_1UP)
if (num > 2) {
#define cpuGRAPH ( GRAPH_prefix_abv + Graph_cpus->length + GRAPH_suffix )
#define nxtGRAPH ( cpuGRAPH + ADJOIN_space )
int len = cpuGRAPH;
for (;;) {
if (len + nxtGRAPH > GRAPH_length_max) break;
len += nxtGRAPH;
}
len -= (GRAPH_prefix_abv + ADJOIN_space);
Graph_mems->length = len;
#undef cpuGRAPH
#undef nxtGRAPH
}
#endif
} else {
Graph_cpus->length = Screen_cols - (GRAPH_prefix_std + GRAPH_length_max + GRAPH_suffix);
if (Graph_cpus->length >= 0) Graph_cpus->length = GRAPH_length_max;
else Graph_cpus->length = Screen_cols - GRAPH_prefix_std - GRAPH_suffix;
Graph_mems->length = Graph_cpus->length;
}
if (Graph_cpus->length < GRAPH_length_min) Graph_cpus->length = GRAPH_length_min;
if (Graph_cpus->length > GRAPH_length_max) Graph_cpus->length = GRAPH_length_max;
#ifdef TOG4_MEM_1UP
Graph_mems->length = (Screen_cols - (GRAPH_prefix_std + GRAPH_suffix));
if (Graph_mems->length > GRAPH_length_max) Graph_mems->length = GRAPH_length_max;
if (Graph_mems->length < GRAPH_length_min) Graph_mems->length = GRAPH_length_min;
#else
Graph_mems->length = Graph_cpus->length;
#endif
}
Graph_cpus->adjust = (float)Graph_cpus->length / 100.0;
Graph_cpus->style = Curwin->rc.graph_cpus;
if (Graph_mems->length < GRAPH_length_min) Graph_mems->length = GRAPH_length_min;
if (Graph_mems->length > GRAPH_length_max) Graph_mems->length = GRAPH_length_max;
Graph_mems->adjust = (float)Graph_mems->length / 100.0;
Graph_mems->style = Curwin->rc.graph_mems;
@ -6582,18 +6607,40 @@ static void do_memory (void) {
Graph_mems->part1 = kb_main_used;
Graph_mems->part2 = kb_main_my_misc;
rx = sum_rx(Graph_mems);
#ifdef TOG4_MEM_1UP
prT(bfT(0), mkM(total));
snprintf(row, sizeof(row), "%s %s:~3%#5.1f~2/%-9.9s~3%s"
, scT(label), N_txt(WORD_abv_mem_txt), rx->pcnt_tot, bfT(0), rx->graph);
#else
if (Curwin->rc.double_up > 1)
snprintf(row, sizeof(row), "%s %s~3%3.0f%s"
, scT(label), N_txt(WORD_abv_mem_txt), rx->pcnt_tot, rx->graph);
else {
prT(bfT(0), mkM(total));
snprintf(row, sizeof(row), "%s %s:~3%#5.1f~2/%-9.9s~3%s"
, scT(label), N_txt(WORD_abv_swp_txt), rx->pcnt_tot, bfT(0), rx->graph);
}
#endif
Msg_row += sum_see(row, mem2UP);
Graph_mems->total = kb_swap_total;
Graph_mems->part1 = 0;
Graph_mems->part2 = kb_main_used;
Graph_mems->part2 = kb_swap_used;
rx = sum_rx(Graph_mems);
#ifdef TOG4_MEM_1UP
prT(bfT(1), mkS(total));
snprintf(row, sizeof(row), "%s %s:~3%#5.1f~2/%-9.9s~3%s"
, scT(label), N_txt(WORD_abv_swp_txt), rx->pcnt_two, bfT(1), rx->graph);
#else
if (Curwin->rc.double_up > 1)
snprintf(row, sizeof(row), "%s %s~3%3.0f%s"
, scT(label), N_txt(WORD_abv_swp_txt), rx->pcnt_two, rx->graph);
else {
prT(bfT(1), mkS(total));
snprintf(row, sizeof(row), "%s %s:~3%#5.1f~2/%-9.9s~3%s"
, scT(label), N_txt(WORD_abv_swp_txt), rx->pcnt_two, bfT(1), rx->graph);
}
#endif
Msg_row += sum_see(row, 1);
} else {

View File

@ -65,6 +65,7 @@
//#define STRINGCASENO /* case insenstive compare/locate versions */
//#define TERMIOS_ONLY /* use native input only (just limp along) */
//#define TOG4_MEM_1UP /* don't show two abreast memory statistic */
//#define TOG4_MEM_FIX /* no variable mem graphs, thus misaligned */
//#define TOG4_SEP_OFF /* don't show two abreast visual separator */
//#define TOG4_SEP_STD /* normal mem sep if 2 abreast & no graphs */
//#define TREE_NORESET /* sort keys should not force 'V' view off */