top: extended 'scale_tics' function for Ctrl-E scaling

That normalization of the 'scale_tics' function in the
prior commit convinced me that I won't please everyone
with my arbitrary choices for the scaling transitions.

So, this patch will provide the users with a means for
setting their own scaling transition points with a new
toggle. Ctrl-E was chosen since the 'e/E' toggles were
already present as a means of scaling (albeit memory).

[ this toggle will also serve an educational purpose ]
[ by allowing one to see all the scaling conventions ]

The scaling a user establishes is saved in the rcfile.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2022-03-03 00:00:00 -06:00 committed by Craig Small
parent 71eb90c1b2
commit 402bf1903b
3 changed files with 30 additions and 8 deletions

View File

@ -1633,6 +1633,8 @@ end_justifies:
#define TICS_AS_SECS 0 #define TICS_AS_SECS 0
#define TICS_AS_MINS 1 #define TICS_AS_MINS 1
#define TICS_AS_HOUR 2 #define TICS_AS_HOUR 2
#define TICS_AS_DAYS 3
#define TICS_AS_WEEK 4
/* /*
* Do some scaling stuff. * Do some scaling stuff.
@ -1698,6 +1700,9 @@ static const char *scale_tics (TIC_t tics, int width, int justr, int target) {
days = (nt /= 24); // totat days days = (nt /= 24); // totat days
week = (nt / 7); // total week week = (nt / 7); // total week
if (Rc.tics_scaled > target)
target += Rc.tics_scaled - target;
switch (target) { switch (target) {
case TICS_AS_SECS: case TICS_AS_SECS:
if (mins < mmLIMIT + 1) { if (mins < mmLIMIT + 1) {
@ -1714,7 +1719,7 @@ static const char *scale_tics (TIC_t tics, int width, int justr, int target) {
if (width >= snprintf(buf, sizeof(buf), "%lu,%02lu", hour, mins % 60)) if (width >= snprintf(buf, sizeof(buf), "%lu,%02lu", hour, mins % 60))
goto end_justifies; goto end_justifies;
} }
default: // fall through case TICS_AS_DAYS: // fall through
if (days < ddLIMIT + 1) { if (days < ddLIMIT + 1) {
if (width >= snprintf(buf, sizeof(buf), DD "+" HH, days, hour % 24)) if (width >= snprintf(buf, sizeof(buf), DD "+" HH, days, hour % 24))
goto end_justifies; goto end_justifies;
@ -1725,6 +1730,7 @@ static const char *scale_tics (TIC_t tics, int width, int justr, int target) {
if (width >= snprintf(buf, sizeof(buf), DD, days)) if (width >= snprintf(buf, sizeof(buf), DD, days))
goto end_justifies; goto end_justifies;
} }
case TICS_AS_WEEK: // fall through
if (width >= snprintf(buf, sizeof(buf), WW "+" DD, week, days % 7)) if (width >= snprintf(buf, sizeof(buf), WW "+" DD, week, days % 7))
goto end_justifies; goto end_justifies;
#ifdef SCALE_POSTFX #ifdef SCALE_POSTFX
@ -1733,6 +1739,7 @@ static const char *scale_tics (TIC_t tics, int width, int justr, int target) {
#endif #endif
if (width >= snprintf(buf, sizeof(buf), WW, week)) if (width >= snprintf(buf, sizeof(buf), WW, week))
goto end_justifies; goto end_justifies;
default: // fall through
break; break;
} }
#undef mmLIMIT #undef mmLIMIT
@ -3846,6 +3853,7 @@ static const char *configs_file (FILE *fp, const char *name, float *delay) {
w->rc.double_up = w->rc.combine_cpus = 0; w->rc.double_up = w->rc.combine_cpus = 0;
// fall through // fall through
case 'j': // this is release 3.3.17 case 'j': // this is release 3.3.17
Rc.tics_scaled = 0;
case 'k': // current RCF_VERSION_ID case 'k': // current RCF_VERSION_ID
default: default:
if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1) if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1)
@ -3866,8 +3874,8 @@ static const char *configs_file (FILE *fp, const char *name, float *delay) {
} // end: for (GROUPSMAX) } // end: for (GROUPSMAX)
// any new addition(s) last, for older rcfiles compatibility... // any new addition(s) last, for older rcfiles compatibility...
(void)fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n" (void)fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d, Tics_scaled=%d\n"
, &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress); , &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress, &Rc.tics_scaled);
if (Rc.fixed_widest < -1 || Rc.fixed_widest > SCREENMAX) if (Rc.fixed_widest < -1 || Rc.fixed_widest > SCREENMAX)
Rc.fixed_widest = 0; Rc.fixed_widest = 0;
if (Rc.summ_mscale < 0 || Rc.summ_mscale > SK_Eb) if (Rc.summ_mscale < 0 || Rc.summ_mscale > SK_Eb)
@ -3876,6 +3884,8 @@ static const char *configs_file (FILE *fp, const char *name, float *delay) {
Rc.task_mscale = 0; Rc.task_mscale = 0;
if (Rc.zero_suppress < 0 || Rc.zero_suppress > 1) if (Rc.zero_suppress < 0 || Rc.zero_suppress > 1)
Rc.zero_suppress = 0; Rc.zero_suppress = 0;
if (Rc.tics_scaled < 0 || Rc.tics_scaled > TICS_AS_WEEK)
Rc.tics_scaled = 0;
// prepare to warn that older top can no longer read rcfile ... // prepare to warn that older top can no longer read rcfile ...
if (Rc.id != RCF_VERSION_ID) if (Rc.id != RCF_VERSION_ID)
@ -4253,7 +4263,10 @@ static void win_reset (WIN_t *q) {
#else #else
q->rc.maxtasks = q->usrseltyp = q->begpflg = q->begtask = q->begnext = q->focus_pid = 0; q->rc.maxtasks = q->usrseltyp = q->begpflg = q->begtask = q->begnext = q->focus_pid = 0;
#endif #endif
// these next two are global, not really windows based
Monpidsidx = 0; Monpidsidx = 0;
Rc.tics_scaled = 0;
osel_clear(q); osel_clear(q);
q->findstr[0] = '\0'; q->findstr[0] = '\0';
#ifndef USE_X_COLHDR #ifndef USE_X_COLHDR
@ -4986,8 +4999,8 @@ static void write_rcfile (void) {
} }
// any new addition(s) last, for older rcfiles compatibility... // any new addition(s) last, for older rcfiles compatibility...
fprintf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n" fprintf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d, Tics_scaled=%d\n"
, Rc.fixed_widest, Rc.summ_mscale, Rc.task_mscale, Rc.zero_suppress); , Rc.fixed_widest, Rc.summ_mscale, Rc.task_mscale, Rc.zero_suppress, Rc.tics_scaled);
if (Winstk[0].osel_tot + Winstk[1].osel_tot if (Winstk[0].osel_tot + Winstk[1].osel_tot
+ Winstk[2].osel_tot + Winstk[3].osel_tot) { + Winstk[2].osel_tot + Winstk[3].osel_tot) {
@ -5140,6 +5153,13 @@ static void keys_global (int ch) {
case '0': case '0':
Rc.zero_suppress = !Rc.zero_suppress; Rc.zero_suppress = !Rc.zero_suppress;
break; break;
case kbd_CtrlE:
#ifndef SCALE_FORMER
Rc.tics_scaled++;
if (Rc.tics_scaled > TICS_AS_WEEK)
Rc.tics_scaled = 0;
#endif
break;
case kbd_ENTER: // these two have the effect of waking us case kbd_ENTER: // these two have the effect of waking us
case kbd_SPACE: // from 'pselect', refreshing the display case kbd_SPACE: // from 'pselect', refreshing the display
break; // and updating any hot-plugged resources break; // and updating any hot-plugged resources
@ -5981,7 +6001,7 @@ static void do_key (int ch) {
{ keys_global, { keys_global,
{ '?', 'B', 'd', 'E', 'e', 'f', 'g', 'H', 'h' { '?', 'B', 'd', 'E', 'e', 'f', 'g', 'H', 'h'
, 'I', 'k', 'r', 's', 'X', 'Y', 'Z', '0' , 'I', 'k', 'r', 's', 'X', 'Y', 'Z', '0'
, kbd_ENTER, kbd_SPACE, '\0' } }, , kbd_CtrlE, kbd_ENTER, kbd_SPACE, '\0' } },
{ keys_summary, { keys_summary,
{ '!', '1', '2', '3', '4', 'C', 'l', 'm', 't', '\0' } }, { '!', '1', '2', '3', '4', 'C', 'l', 'm', 't', '\0' } },
{ keys_task, { keys_task,

View File

@ -170,6 +170,7 @@ char *strcasestr(const char *haystack, const char *needle);
#define kbd_INS 138 #define kbd_INS 138
#define kbd_DEL 139 #define kbd_DEL 139
#define kbd_CtrlO '\017' #define kbd_CtrlO '\017'
#define kbd_CtrlE '\005'
/* Special value in Pseudo_row to force an additional procs refresh /* Special value in Pseudo_row to force an additional procs refresh
-- used at startup and for task/thread mode transitions */ -- used at startup and for task/thread mode transitions */
@ -331,6 +332,7 @@ typedef struct RCF_t {
int summ_mscale; // 'E' - scaling of summary memory values int summ_mscale; // 'E' - scaling of summary memory values
int task_mscale; // 'e' - scaling of process memory values int task_mscale; // 'e' - scaling of process memory values
int zero_suppress; // '0' - suppress scaled zeros toggle int zero_suppress; // '0' - suppress scaled zeros toggle
int tics_scaled; // ^E - scale TIME and/or TIME+ columns
} RCF_t; } RCF_t;
/* This structure stores configurable information for each window. /* This structure stores configurable information for each window.
@ -548,7 +550,7 @@ typedef struct WIN_t {
{ EU_UEN, ALT_WINFLGS, 0, ALT_GRAPHS2, 0, 0, \ { EU_UEN, ALT_WINFLGS, 0, ALT_GRAPHS2, 0, 0, \
COLOR_YELLOW, COLOR_YELLOW, COLOR_GREEN, COLOR_YELLOW, \ COLOR_YELLOW, COLOR_YELLOW, COLOR_GREEN, COLOR_YELLOW, \
"Usr", USR_FIELDS } \ "Usr", USR_FIELDS } \
}, 0, DEF_SCALES2, 0 } }, 0, DEF_SCALES2, 0, 0 }
/* Summary Lines specially formatted string(s) -- /* Summary Lines specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */ see 'show_special' for syntax details + other cautions. */

View File

@ -644,7 +644,7 @@ static void build_uniq_nlstab (void) {
" V,v,F . Toggle: '~1V~2' forest view; '~1v~2' hide/show children; '~1F~2' keep focused\n" " V,v,F . Toggle: '~1V~2' forest view; '~1v~2' hide/show children; '~1F~2' keep focused\n"
"\n" "\n"
"%s" "%s"
" W,Y,! Write config file '~1W~2'; Inspect other output '~1Y~2'; Combine Cpus '~1!~2'\n" " W,Y,!,^E Write cfg '~1W~2'; Inspect '~1Y~2'; Combine Cpus '~1!~2'; Scale time ~1Ctrl~2+'~1E~2'\n"
" q Quit\n" " q Quit\n"
" ( commands shown with '.' require a ~1visible~2 task display ~1window~2 ) \n" " ( commands shown with '.' require a ~1visible~2 task display ~1window~2 ) \n"
"Press '~1h~2' or '~1?~2' for help with ~1Windows~2,\n" "Press '~1h~2' or '~1?~2' for help with ~1Windows~2,\n"