top: rework bottom 'window' logic to reduce redundancy <=== port of newlib ef1d82cf
______________________________ original newlib message This patch attempts to reduce the proliferation of the bottom window support routines by combining the 'misc' with 'item' functions. Along the way we can now rename those two 'pick' functions 'menu' while keeping proper alphabetic order among all the bottom window routines. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
1556ee519c
commit
b4c17fd544
163
top/top.c
163
top/top.c
@ -112,13 +112,12 @@ static int Monpidsidx = 0;
|
|||||||
/* Current terminal screen size. */
|
/* Current terminal screen size. */
|
||||||
static int Screen_cols, Screen_rows, Max_lines;
|
static int Screen_cols, Screen_rows, Max_lines;
|
||||||
|
|
||||||
// these are for the special separate bottom 'window'
|
/* These 'SCREEN_ROWS', 'BOT_ and 'Bot_' guys are used
|
||||||
|
in managing the special separate bottom 'window' ... */
|
||||||
#define SCREEN_ROWS ( Screen_rows - Bot_rsvd )
|
#define SCREEN_ROWS ( Screen_rows - Bot_rsvd )
|
||||||
#define BOT_UNFOCUS -1 // tab focus not established
|
#define BOT_UNFOCUS -1 // tab focus not established
|
||||||
#define BOT_TAB_YES -1 // tab focus could be active
|
|
||||||
#define BOT_MISC_NS +1 // data for namespaces req'd
|
|
||||||
#ifdef BOT_MENU_YES
|
#ifdef BOT_MENU_YES
|
||||||
# define BOT_MENU_ON -2 // in menu, tab focus active
|
# define BOT_MENU_ON -3 // in menu, tab focus active
|
||||||
#endif
|
#endif
|
||||||
// next 4 are used when toggling window contents
|
// next 4 are used when toggling window contents
|
||||||
#define BOT_SEP_CMA ','
|
#define BOT_SEP_CMA ','
|
||||||
@ -130,21 +129,20 @@ static int Screen_cols, Screen_rows, Max_lines;
|
|||||||
// 1 for horizontal separator
|
// 1 for horizontal separator
|
||||||
#define BOT_RSVD 1
|
#define BOT_RSVD 1
|
||||||
#define BOT_KEEP Bot_show_func = NULL
|
#define BOT_KEEP Bot_show_func = NULL
|
||||||
#define BOT_TOSS do { Bot_show_func = NULL; Bot_lflg = 0; \
|
#define BOT_TOSS do { Bot_show_func = NULL; \
|
||||||
Bot_task = Bot_rsvd = Bot_what = 0; \
|
Bot_task = Bot_rsvd = Bot_what = 0; \
|
||||||
Bot_indx = BOT_UNFOCUS; \
|
Bot_indx = BOT_UNFOCUS; \
|
||||||
} while(0)
|
} while(0)
|
||||||
static int Bot_task,
|
static int Bot_task,
|
||||||
Bot_what,
|
Bot_what,
|
||||||
Bot_rsvd,
|
Bot_rsvd,
|
||||||
Bot_indx = BOT_UNFOCUS,
|
Bot_indx = BOT_UNFOCUS;
|
||||||
Bot_lflg;
|
static char Bot_sep,
|
||||||
static char *Bot_name,
|
*Bot_name,
|
||||||
Bot_sep;
|
Bot_buf[BOTBUFSIZ]; // the 'environ' can be huge
|
||||||
typedef int(*BOT_f)(const void *, const void *);
|
typedef int(*BOT_f)(const void *, const void *);
|
||||||
static BOT_f Bot_focus_func;
|
static BOT_f Bot_focus_func;
|
||||||
static void(*Bot_show_func)(void);
|
static void(*Bot_show_func)(void);
|
||||||
static char Bot_buf[BOTBUFSIZ]; // the 'environ' can be huge
|
|
||||||
|
|
||||||
/* This is really the number of lines needed to display the summary
|
/* This is really the number of lines needed to display the summary
|
||||||
information (0 - nn), but is used as the relative row where we
|
information (0 - nn), but is used as the relative row where we
|
||||||
@ -2165,7 +2163,7 @@ static void build_headers (void) {
|
|||||||
if (w->usrseltyp == 'U') Frames_libflags |= L_status;
|
if (w->usrseltyp == 'U') Frames_libflags |= L_status;
|
||||||
|
|
||||||
// lastly, accommodate any special non-display 'tagged' needs...
|
// lastly, accommodate any special non-display 'tagged' needs...
|
||||||
Frames_libflags |= Bot_lflg;
|
Frames_libflags |= Bot_what;
|
||||||
} // end: VIZISw(w)
|
} // end: VIZISw(w)
|
||||||
|
|
||||||
if (Rc.mode_altscr) w = w->next;
|
if (Rc.mode_altscr) w = w->next;
|
||||||
@ -5138,7 +5136,7 @@ static int bot_focus_str (const char *hdr, const char *str) {
|
|||||||
else memccpy(Bot_buf, str, '\0', n);
|
else memccpy(Bot_buf, str, '\0', n);
|
||||||
Bot_rsvd = 1 + BOT_RSVD + (strlen(Bot_buf) / Screen_cols);
|
Bot_rsvd = 1 + BOT_RSVD + (strlen(Bot_buf) / Screen_cols);
|
||||||
if (Bot_rsvd > maxRSVD) Bot_rsvd = maxRSVD;
|
if (Bot_rsvd > maxRSVD) Bot_rsvd = maxRSVD;
|
||||||
// caller itself may have used fmtmk, so we'll old school it ...
|
// somewhere down call chain fmtmk() may be used, so we'll old school it
|
||||||
snprintf(tmp, sizeof(tmp), "%s%s%-*s", tg2(0, SCREEN_ROWS), Curwin->capclr_hdr, Screen_cols, hdr);
|
snprintf(tmp, sizeof(tmp), "%s%s%-*s", tg2(0, SCREEN_ROWS), Curwin->capclr_hdr, Screen_cols, hdr);
|
||||||
putp(tmp);
|
putp(tmp);
|
||||||
}
|
}
|
||||||
@ -5191,7 +5189,7 @@ static int bot_focus_strv (const char *hdr, const char **strv) {
|
|||||||
}
|
}
|
||||||
Bot_rsvd = 1 + BOT_RSVD + (n / Screen_cols);
|
Bot_rsvd = 1 + BOT_RSVD + (n / Screen_cols);
|
||||||
if (Bot_rsvd > maxRSVD) Bot_rsvd = maxRSVD;
|
if (Bot_rsvd > maxRSVD) Bot_rsvd = maxRSVD;
|
||||||
// caller itself may have used fmtmk, so we'll old school it ...
|
// somewhere down call chain fmtmk() may be used, so we'll old school it
|
||||||
snprintf(tmp, sizeof(tmp), "%s%s%-*s", tg2(0, SCREEN_ROWS), Curwin->capclr_hdr, Screen_cols, hdr);
|
snprintf(tmp, sizeof(tmp), "%s%s%-*s", tg2(0, SCREEN_ROWS), Curwin->capclr_hdr, Screen_cols, hdr);
|
||||||
putp(tmp);
|
putp(tmp);
|
||||||
}
|
}
|
||||||
@ -5211,89 +5209,20 @@ static int bot_focus_strv (const char *hdr, const char **strv) {
|
|||||||
} // end: bot_focus_strv
|
} // end: bot_focus_strv
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This guy manages the bottom margin window, |
|
|
||||||
* showing miscellaneous variable width data. | */
|
|
||||||
static void bot_item_show (void) {
|
|
||||||
#define mkHDR fmtmk("%s for pid %d, %s", Bot_name, Bot_task, p->cmd)
|
|
||||||
#define cmdLN PROC_FILLCOM | PROC_FILLARG
|
|
||||||
proc_t *p;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < Frame_maxtask; i++) {
|
|
||||||
p = Curwin->ppt[i];
|
|
||||||
if (Bot_task == p->tid)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i < Frame_maxtask) {
|
|
||||||
switch (Bot_lflg) {
|
|
||||||
case (L_CGROUP): // Ctrl-G
|
|
||||||
bot_focus_str(mkHDR, *p->cgroup);
|
|
||||||
break;
|
|
||||||
case (cmdLN): // Ctrl-K
|
|
||||||
bot_focus_strv(mkHDR, (const char**)p->cmdline);
|
|
||||||
break;
|
|
||||||
case (PROC_FILLENV): // Ctrl-N
|
|
||||||
bot_focus_strv(mkHDR, (const char**)p->environ);
|
|
||||||
break;
|
|
||||||
case (L_SUPGRP): // Ctrl-U
|
|
||||||
bot_focus_str(mkHDR, p->supgrp);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef Bot_DEATH
|
|
||||||
else
|
|
||||||
BOT_TOSS;
|
|
||||||
#else
|
|
||||||
BOT_KEEP;
|
|
||||||
#endif
|
|
||||||
#undef mkHDR
|
|
||||||
#undef cmdLN
|
|
||||||
} // end: bot_item_show
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This guy toggles between displaying a Ctrl |
|
|
||||||
* bottom window or arranging to turn it off. | */
|
|
||||||
static void bot_item_toggle (int flg, const char *str, char sep) {
|
|
||||||
// if already targeted, assume user wants to turn it off ...
|
|
||||||
if (Bot_lflg == flg) {
|
|
||||||
BOT_TOSS;
|
|
||||||
} else {
|
|
||||||
Bot_lflg = flg;
|
|
||||||
Bot_sep = sep;
|
|
||||||
Bot_what = BOT_TAB_YES;
|
|
||||||
Bot_indx = BOT_UNFOCUS;
|
|
||||||
Bot_name = (char*)str;
|
|
||||||
switch (flg) {
|
|
||||||
case PROC_FILLCOM:
|
|
||||||
case PROC_FILLARG:
|
|
||||||
case PROC_FILLENV:
|
|
||||||
Bot_focus_func = (BOT_f)bot_focus_strv;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Bot_focus_func = (BOT_f)bot_focus_str;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Bot_show_func = bot_item_show;
|
|
||||||
Bot_task = Curwin->ppt[Curwin->begtask]->tid;
|
|
||||||
}
|
|
||||||
} // end: bot_item_toggle
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A helper function that will gather various |
|
* A helper function that will gather various |
|
||||||
* stuff for dislay by the bot_misc_show guy. | */
|
* stuff for dislay by the bot_item_show guy. | */
|
||||||
static char *bot_misc_hlp (proc_t *p) {
|
static void *bot_item_hlp (proc_t *p) {
|
||||||
static enum ns_type ns_tab[] = {
|
static enum ns_type ns_tab[] = {
|
||||||
// eu_ns1 eu_ns2 eu_ns3 eu_ns4 eu_ns5 eu_ns6
|
// eu_ns1 eu_ns2 eu_ns3 eu_ns4 eu_ns5 eu_ns6
|
||||||
IPCNS, MNTNS, NETNS, PIDNS, USERNS, UTSNS };
|
IPCNS, MNTNS, NETNS, PIDNS, USERNS, UTSNS };
|
||||||
static char tmp[SMLBUFSIZ], buf[BIGBUFSIZ], *b;
|
static char buf[BIGBUFSIZ];
|
||||||
|
char tmp[SMLBUFSIZ], *b;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
switch (Bot_what) {
|
switch (Bot_what) {
|
||||||
case BOT_MISC_NS:
|
case (L_NS):
|
||||||
b = &buf[0];
|
b = &buf[0];
|
||||||
for (i = 0; i < MAXTBL(ns_tab); i++) {
|
for (i = 0; i < MAXTBL(ns_tab); i++) {
|
||||||
// caller itself may have used fmtmk, so we'll old school it ...
|
// caller itself may have used fmtmk, so we'll old school it ...
|
||||||
@ -5303,18 +5232,24 @@ static char *bot_misc_hlp (proc_t *p) {
|
|||||||
b = scat(b, tmp);
|
b = scat(b, tmp);
|
||||||
if (i < (MAXTBL(ns_tab) - 1)) b = scat(b, ", ");
|
if (i < (MAXTBL(ns_tab) - 1)) b = scat(b, ", ");
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return buf;
|
return buf;
|
||||||
} // end: bot_misc_hlp
|
case (L_CGROUP):
|
||||||
|
return *p->cgroup;
|
||||||
|
case (L_SUPGRP):
|
||||||
|
return p->supgrp;
|
||||||
|
case PROC_FILLENV:
|
||||||
|
return p->environ;
|
||||||
|
case PROC_FILLARG:
|
||||||
|
default:
|
||||||
|
return p->cmdline;
|
||||||
|
}
|
||||||
|
} // end: bot_item_hlp
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This guy manages the bottom margin window, |
|
* This guy manages the bottom margin window, |
|
||||||
* showing misc data based on multiple items. | */
|
* showing miscellaneous variable width data. | */
|
||||||
static void bot_misc_show (void) {
|
static void bot_item_show (void) {
|
||||||
#define mkHDR fmtmk("%s for pid %d, %s", Bot_name, Bot_task, p->cmd)
|
#define mkHDR fmtmk("%s for pid %d, %s", Bot_name, Bot_task, p->cmd)
|
||||||
proc_t *p;
|
proc_t *p;
|
||||||
int i;
|
int i;
|
||||||
@ -5325,7 +5260,7 @@ static void bot_misc_show (void) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (i < Frame_maxtask) {
|
if (i < Frame_maxtask) {
|
||||||
Bot_focus_func(mkHDR, bot_misc_hlp(p));
|
Bot_focus_func(mkHDR, bot_item_hlp(p));
|
||||||
}
|
}
|
||||||
#ifdef Bot_DEATH
|
#ifdef Bot_DEATH
|
||||||
else
|
else
|
||||||
@ -5334,49 +5269,51 @@ static void bot_misc_show (void) {
|
|||||||
BOT_KEEP;
|
BOT_KEEP;
|
||||||
#endif
|
#endif
|
||||||
#undef mkHDR
|
#undef mkHDR
|
||||||
} // end: bot_misc_show
|
} // end: bot_item_show
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This guy toggles between displaying a Ctrl |
|
* This guy toggles between displaying a Ctrl |
|
||||||
* bottom window or arranging to turn it off. | */
|
* bottom window or arranging to turn it off. | */
|
||||||
static void bot_misc_toggle (int what, char sep) {
|
static void bot_item_toggle (int what, const char *name, char sep) {
|
||||||
// if already targeted, assume user wants to turn it off ...
|
// if already targeted, assume user wants to turn it off ...
|
||||||
if (Bot_what == what) {
|
if (Bot_what == what) {
|
||||||
BOT_TOSS;
|
BOT_TOSS;
|
||||||
} else {
|
} else {
|
||||||
switch (what) {
|
switch (what) {
|
||||||
case BOT_MISC_NS:
|
case PROC_FILLARG:
|
||||||
Bot_lflg = L_NS;
|
case PROC_FILLENV:
|
||||||
Bot_name = (char*)"namespaces";
|
Bot_focus_func = (BOT_f)bot_focus_strv;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Bot_focus_func = (BOT_f)bot_focus_str;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Bot_what = what;
|
||||||
Bot_sep = sep;
|
Bot_sep = sep;
|
||||||
Bot_what = what;
|
Bot_what = what;
|
||||||
Bot_indx = BOT_UNFOCUS;
|
Bot_indx = BOT_UNFOCUS;
|
||||||
Bot_focus_func = (BOT_f)bot_focus_str;
|
Bot_name = (char *)name;
|
||||||
Bot_show_func = bot_misc_show;
|
Bot_show_func = bot_item_show;
|
||||||
Bot_task = Curwin->ppt[Curwin->begtask]->tid;
|
Bot_task = Curwin->ppt[Curwin->begtask]->tid;
|
||||||
}
|
}
|
||||||
} // end: bot_misc_toggle
|
} // end: bot_item_toggle
|
||||||
|
|
||||||
|
|
||||||
#ifdef BOT_MENU_YES
|
#ifdef BOT_MENU_YES
|
||||||
/*
|
/*
|
||||||
* This guy manages that bottom margin window |
|
* This guy manages that bottom margin window |
|
||||||
* when it is used as a menu of user choices. | */
|
* when it is used as a menu of user choices. | */
|
||||||
static void bot_pick_show (void) {
|
static void bot_menu_show (void) {
|
||||||
Bot_focus_func(Bot_name, "selection #1\t selection #2\t selecttion #3");
|
Bot_focus_func(Bot_name, "selection #1\t selection #2\t selecttion #3");
|
||||||
BOT_KEEP;
|
BOT_KEEP;
|
||||||
} // end: bot_pick_show
|
} // end: bot_menu_show
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This guy can toggle between displaying the |
|
* This guy can toggle between displaying the |
|
||||||
* bottom window or arranging to turn it off. | */
|
* bottom window or arranging to turn it off. | */
|
||||||
static void bot_pick_toggle (void) {
|
static void bot_menu_toggle (void) {
|
||||||
// if already in menu mode, assume user wants to exit ...
|
// if already in menu mode, assume user wants to exit ...
|
||||||
if (Bot_what == BOT_MENU_ON) {
|
if (Bot_what == BOT_MENU_ON) {
|
||||||
BOT_TOSS;
|
BOT_TOSS;
|
||||||
@ -5386,10 +5323,10 @@ static void bot_pick_toggle (void) {
|
|||||||
Bot_indx = 0;
|
Bot_indx = 0;
|
||||||
Bot_name = (char *)"a menu, please choose among the following, then press <Enter> ...";
|
Bot_name = (char *)"a menu, please choose among the following, then press <Enter> ...";
|
||||||
Bot_focus_func = (BOT_f)bot_focus_str;
|
Bot_focus_func = (BOT_f)bot_focus_str;
|
||||||
Bot_show_func = bot_pick_show;
|
Bot_show_func = bot_menu_show;
|
||||||
Bot_task = Curwin->ppt[Curwin->begtask]->tid;
|
Bot_task = Curwin->ppt[Curwin->begtask]->tid;
|
||||||
}
|
}
|
||||||
} // end: bot_pick_toggle
|
} // end: bot_menu_toggle
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*###### Interactive Input Tertiary support ############################*/
|
/*###### Interactive Input Tertiary support ############################*/
|
||||||
@ -5761,11 +5698,11 @@ static void keys_global (int ch) {
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case kbd_CtrlG:
|
case kbd_CtrlG:
|
||||||
bot_item_toggle(L_CGROUP, "control groups", BOT_SEP_SLS);
|
bot_item_toggle((L_CGROUP), "control groups", BOT_SEP_SLS);
|
||||||
break;
|
break;
|
||||||
#ifdef BOT_MENU_YES
|
#ifdef BOT_MENU_YES
|
||||||
case kbd_CtrlH:
|
case kbd_CtrlH:
|
||||||
bot_pick_toggle();
|
bot_menu_toggle();
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case kbd_CtrlI:
|
case kbd_CtrlI:
|
||||||
@ -5777,17 +5714,17 @@ static void keys_global (int ch) {
|
|||||||
break;
|
break;
|
||||||
case kbd_CtrlK:
|
case kbd_CtrlK:
|
||||||
// with string vectors, the 'separator' may serve a different purpose
|
// with string vectors, the 'separator' may serve a different purpose
|
||||||
bot_item_toggle(PROC_FILLCOM|PROC_FILLARG, "command line", BOT_SEP_SPC);
|
bot_item_toggle(PROC_FILLARG, "command line", BOT_SEP_SPC);
|
||||||
break;
|
break;
|
||||||
case kbd_CtrlN:
|
case kbd_CtrlN:
|
||||||
// with string vectors, the 'separator' may serve a different purpose
|
// with string vectors, the 'separator' may serve a different purpose
|
||||||
bot_item_toggle(PROC_FILLENV, "environment", BOT_SEP_SPC);
|
bot_item_toggle(PROC_FILLENV, "environment", BOT_SEP_SPC);
|
||||||
break;
|
break;
|
||||||
case kbd_CtrlP:
|
case kbd_CtrlP:
|
||||||
bot_misc_toggle(BOT_MISC_NS, ',');
|
bot_item_toggle((L_NS), "namespaces", BOT_SEP_CMA);
|
||||||
break;
|
break;
|
||||||
case kbd_CtrlU:
|
case kbd_CtrlU:
|
||||||
bot_item_toggle(L_SUPGRP, "supplementary groups", BOT_SEP_CMA);
|
bot_item_toggle((L_SUPGRP), "supplementary groups", BOT_SEP_CMA);
|
||||||
break;
|
break;
|
||||||
case kbd_BTAB:
|
case kbd_BTAB:
|
||||||
if (Bot_what) {
|
if (Bot_what) {
|
||||||
|
10
top/top.h
10
top/top.h
@ -834,14 +834,12 @@ typedef struct WIN_t {
|
|||||||
//atic void bot_do (const char *str, int focus);
|
//atic void bot_do (const char *str, int focus);
|
||||||
//atic int bot_focus_str (const char *hdr, const char *str);
|
//atic int bot_focus_str (const char *hdr, const char *str);
|
||||||
//atic int bot_focus_strv (const char *hdr, const char **strv);
|
//atic int bot_focus_strv (const char *hdr, const char **strv);
|
||||||
|
//atic void *bot_item_hlp (proc_t *p);
|
||||||
//atic void bot_item_show (void);
|
//atic void bot_item_show (void);
|
||||||
//atic void bot_item_toggle (int item, const char *name, char sep);
|
//atic void bot_item_toggle (int what, const char *name, char sep);
|
||||||
//atic char *bot_misc_hlp (proc_t *p);
|
|
||||||
//atic void bot_misc_show (void);
|
|
||||||
//atic void bot_misc_toggle (int what, char sep);
|
|
||||||
#ifdef BOT_MENU_YES
|
#ifdef BOT_MENU_YES
|
||||||
//atic void bot_pick_show (void);
|
//atic void bot_menu_show (void);
|
||||||
//atic void bot_pick_toggle (void);
|
//atic void bot_menu_toggle (void);
|
||||||
#endif
|
#endif
|
||||||
/*------ Interactive Input Tertiary support ----------------------------*/
|
/*------ Interactive Input Tertiary support ----------------------------*/
|
||||||
//atic inline int find_ofs (const WIN_t *q, const char *buf);
|
//atic inline int find_ofs (const WIN_t *q, const char *buf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user