aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/top/commands.c
diff options
context:
space:
mode:
authorEitan Adler <eadler@FreeBSD.org>2018-06-13 08:52:06 +0000
committerEitan Adler <eadler@FreeBSD.org>2018-06-13 08:52:06 +0000
commite7cb1c0776219a9e76628860b0d96aff3556be65 (patch)
tree184fe8345ed3519ec006370ee9786d204d461cd7 /usr.bin/top/commands.c
parentbaab2cf8216f33adfad28ccb8206cf4d2e7e0e2c (diff)
downloadsrc-e7cb1c0776219a9e76628860b0d96aff3556be65.tar.gz
src-e7cb1c0776219a9e76628860b0d96aff3556be65.zip
top(1): format help more nicely
For entries that are duplicates present them nicely rather than showing two identical help entries. For ' ' present it as SPC
Notes
Notes: svn path=/head/; revision=335037
Diffstat (limited to 'usr.bin/top/commands.c')
-rw-r--r--usr.bin/top/commands.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/usr.bin/top/commands.c b/usr.bin/top/commands.c
index 1c5a0fe84333..5b096141316f 100644
--- a/usr.bin/top/commands.c
+++ b/usr.bin/top/commands.c
@@ -57,16 +57,16 @@ const struct command all_commands[] =
{'e', "list errors generated by last \"kill\" or \"renice\" command", false, CMD_errors},
{'H', "toggle the displaying of threads", false, CMD_thrtog},
{'h', "show this help text", true, CMD_help},
- {'?', "show this help text", true, CMD_help},
+ {'?', NULL, true, CMD_help},
{'i', "toggle the displaying of idle processes", false, CMD_idletog},
- {'I', "toggle the displaying of idle processes", false, CMD_idletog},
+ {'I', NULL, false, CMD_idletog},
{'j', "toggle the displaying of jail ID", false, CMD_jidtog},
{'J', "display processes for only one jail (+ selects all jails)", false, CMD_jail},
{'k', "kill processes; send a signal to a list of processes", false, CMD_kill},
{'q', "quit" , true, CMD_quit},
{'m', "toggle the display between 'cpu' and 'io' modes", false, CMD_viewtog},
{'n', "change number of processes to display", false, CMD_number},
- {'#', "change number of processes to display", false, CMD_number},
+ {'#', NULL, false, CMD_number},
{'o', "specify the sort order", false, CMD_order},
{'p', "display one process (+ selects all processes)", false, CMD_pid},
{'P', "toggle the displaying of per-CPU statistics", false, CMD_pcputog},
@@ -86,7 +86,9 @@ const struct command all_commands[] =
void
show_help(void)
{
- const struct command *curcmd;
+ const struct command *curcmd, *nextcmd;
+ char keys[8] = "";
+ _Static_assert(sizeof(keys) >= sizeof("a or b"), "keys right size");
printf("Top version FreeBSD, %s\n", copyright);
curcmd = all_commands;
@@ -95,7 +97,22 @@ show_help(void)
++curcmd;
continue;
}
- printf("%c\t- %s\n", curcmd->c, curcmd->desc);
+ if (curcmd->desc == NULL) {
+ /* we already printed this */
+ ++curcmd;
+ continue;
+ }
+ nextcmd = curcmd + 1;
+ if (nextcmd->desc == NULL && nextcmd->c != '\0') {
+ sprintf(keys, "%c or %c", curcmd->c, nextcmd->c);
+ } else if (curcmd->c == ' '){
+ /* special case space rather than introducing a "display string" to
+ * the struct */
+ sprintf(keys, "SPC");
+ } else {
+ sprintf(keys, "%c", curcmd->c);
+ }
+ printf("%s\t- %s\n", keys, curcmd->desc);
++curcmd;
}
if (overstrike)