top: refactor the 'scroll coordinates' message support

This patch is simply preparation for upcoming vertical
scrolling enhancements. With those changes, it will be
impossible to predict what the beginning task position
should be at the time the message is currently issued.

This patch will allow such a message to be shown after
the individual windows' tasks have all been displayed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2018-06-20 00:00:00 -05:00 committed by Craig Small
parent 97eb4388c6
commit a8dc1a6e5a
3 changed files with 33 additions and 45 deletions

View File

@ -100,10 +100,6 @@ static int Screen_cols, Screen_rows, Max_lines;
stick the cursor between frames. */
static int Msg_row;
/* The nearly complete scroll coordinates message for the current
window, built at the time column headers are constructed */
static char Scroll_fmts [SMLBUFSIZ];
/* Global/Non-windows mode stuff that is NOT persistent */
static int Batch = 0, // batch mode, collect no input, dumb output
Loops = -1, // number of iterations, -1 loops forever
@ -729,6 +725,32 @@ static int show_pmt (const char *str) {
} // end: show_pmt
/*
* Create and print the optional scroll coordinates message */
static void show_scroll (void) {
char tmp1[SMLBUFSIZ], tmp2[SMLBUFSIZ];
int totpflgs = Curwin->totpflgs;
int begpflgs = Curwin->begpflg + 1;
#ifndef USE_X_COLHDR
if (CHKw(Curwin, Show_HICOLS)) {
totpflgs -= 2;
if (ENUpos(Curwin, Curwin->rc.sortindx) < Curwin->begpflg) begpflgs -= 2;
}
#endif
if (1 > totpflgs) totpflgs = 1;
if (1 > begpflgs) begpflgs = 1;
snprintf(tmp1, sizeof(tmp1), N_fmt(SCROLL_coord_fmt), Curwin->begtask + 1, PIDSmaxt, begpflgs, totpflgs);
#ifndef SCROLLVAR_NO
if (Curwin->varcolbeg) {
snprintf(tmp2, sizeof(tmp2), " + %d", Curwin->varcolbeg);
scat(tmp1, tmp2);
}
#endif
PUTT("%s%s %.*s%s", tg2(0, Msg_row), Caps_off, Screen_cols - 3, tmp1, Cap_clr_eol);
} // end: show_scroll
/*
* Show lines with specially formatted elements, but only output
* what will fit within the current screen width.
@ -835,36 +857,6 @@ static void show_special (int interact, const char *glob) {
'fit-to-screen' thingy while also leaving room for the cursor... */
if (*glob) PUTT("%.*s", utf8_embody(glob, Screen_cols - 1), glob);
} // end: show_special
/*
* Create a nearly complete scroll coordinates message, but still
* a format string since we'll be missing the current total tasks. */
static void updt_scroll_msg (void) {
char tmp1[SMLBUFSIZ], tmp2[SMLBUFSIZ];
int totpflgs = Curwin->totpflgs;
int begpflgs = Curwin->begpflg + 1;
#ifndef USE_X_COLHDR
if (CHKw(Curwin, Show_HICOLS)) {
totpflgs -= 2;
if (ENUpos(Curwin, Curwin->rc.sortindx) < Curwin->begpflg) begpflgs -= 2;
}
#endif
if (1 > totpflgs) totpflgs = 1;
if (1 > begpflgs) begpflgs = 1;
snprintf(tmp1, sizeof(tmp1)
, N_fmt(SCROLL_coord_fmt), Curwin->begtask + 1, begpflgs, totpflgs);
strcpy(tmp2, tmp1);
#ifndef SCROLLVAR_NO
if (Curwin->varcolbeg)
snprintf(tmp2, sizeof(tmp2), "%s + %d", tmp1, Curwin->varcolbeg);
#endif
// this Scroll_fmts string no longer provides for termcap tgoto so that
// the usage timing is critical -- see frame_make() for additional info
snprintf(Scroll_fmts, sizeof(Scroll_fmts)
, "%s %.*s%s", Caps_off, Screen_cols - 3, tmp2, Cap_clr_eol);
} // end: updt_scroll_msg
/*###### Low Level Memory/Keyboard/File I/O support ####################*/
@ -1952,9 +1944,6 @@ static void calibrate_fields (void) {
if ((rc = procps_pids_reset(Pids_ctx, Pids_itms, Pids_itms_cur)))
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__, strerror(-rc)));
if (CHKw(Curwin, View_SCROLL))
updt_scroll_msg();
} // end: calibrate_fields
@ -5820,12 +5809,8 @@ static void frame_make (void) {
Max_lines = (Screen_rows - Msg_row) - 1;
OFFw(w, INFINDS_xxx);
/* one way or another, rid us of any prior frame's msg
[ now that this is positioned after the call to summary_show(), ]
[ we no longer need or employ tg2(0, Msg_row) since all summary ]
[ lines end with a newline, and header lines begin with newline ] */
if (VIZISw(w) && CHKw(w, View_SCROLL)) PUTT(Scroll_fmts, PIDSmaxt);
else putp(Cap_clr_eol);
// we're now on Msg_row so clear out any residual messages ...
putp(Cap_clr_eol);
if (!Rc.mode_altscr) {
// only 1 window to show so, piece o' cake
@ -5848,6 +5833,9 @@ static void frame_make (void) {
putp(Cap_nl_clreos);
PSU_CLREOS(Pseudo_row);
}
if (CHKw(w, View_SCROLL) && VIZISw(Curwin))
show_scroll();
fflush(stdout);
/* we'll deem any terminal not supporting tgoto as dumb and disable

View File

@ -565,8 +565,8 @@ typedef struct WIN_t {
//atic void capsmk (WIN_t *q);
//atic void show_msg (const char *str);
//atic int show_pmt (const char *str);
//atic void show_scroll (void);
//atic void show_special (int interact, const char *glob);
//atic void updt_scroll_msg (void);
/*------ Low Level Memory/Keyboard/File I/O support --------------------*/
//atic void *alloc_c (size_t num);
//atic void *alloc_r (void *ptr, size_t num);

View File

@ -377,7 +377,7 @@ static void build_norm_nlstab (void) {
Norm_nlstab[BAD_max_task_txt] = _("Invalid maximum");
Norm_nlstab[GET_user_ids_txt] = _("Which user (blank for all)");
Norm_nlstab[UNKNOWN_cmds_txt] = _("Unknown command - try 'h' for help");
Norm_nlstab[SCROLL_coord_fmt] = _("scroll coordinates: y = %d/%%d (tasks), x = %d/%d (fields)");
Norm_nlstab[SCROLL_coord_fmt] = _("scroll coordinates: y = %d/%d (tasks), x = %d/%d (fields)");
Norm_nlstab[FAIL_alloc_c_txt] = _("failed memory allocate");
Norm_nlstab[FAIL_alloc_r_txt] = _("failed memory re-allocate");
Norm_nlstab[BAD_numfloat_txt] = _("Unacceptable floating point");