I send out an earlier version of this diff to Anindya with some positive
feedback. Instead of claiming another binding, why not make help, order
and view a toggle? I see no reason why this information should disappear
on the next input.
Seems to work fine in my testing.
OK?
martijn@
On Thu, 2021-03-04 at 22:47 -0800, Anindya Mukherjee wrote:
> Hi,
>
> I have reworked my proposed interface for sticky displays in systat
> following earlier feedback. Thanks for that! It helped me rethink the
> interface carefully.
>
> In the current version, sticky mode has its own toggle: ^T. From a study
> of the source and the man page it does not seem to be bound to anything
> and, on my system at least, does not conflict with anything else. I
> could add a dedicated command for it as well if that's useful. The
> current version supports a sticky display for the view list, view mode
> plus refresh interval, and available orderings.
>
> I have tried the hotkeys for the various views as documented in the man
> page (as well as some of the undocumented ones) and they seem to work. I
> have also tried to make sure that the sticky displays don't interfere
> with error messages. In future I would like to try to clean up the view
> hotkeys, which conflict each other in some cases, and seem to be
> undocumented. I found them useful; at least the ones that work. Please
> have a look, thanks!
>
> Regards,
> Anindya
Index: engine.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/engine.c,v
retrieving revision 1.27
diff -u -p -r1.27 engine.c
--- engine.c 6 Feb 2021 06:19:28 -0000 1.27
+++ engine.c 9 Mar 2021 18:32:24 -0000
@@ -91,6 +91,8 @@ char cmdbuf[MAX_LINE_BUF];
int cmd_len = -1;
struct command *curr_cmd = NULL;
char *curr_message = NULL;
+enum message_mode message_mode = MESSAGE_NONE;
+int message_cont = 1;
void print_cmdline(void);
@@ -1145,14 +1147,26 @@ command_set(struct command *cmd, const c
return prev;
}
+void
+message_toggle(enum message_mode mode)
+{
+ message_mode = message_mode != mode ? mode : MESSAGE_NONE;
+ need_update = 1;
+ message_cont = 1;
+}
+
const char *
-message_set(const char *msg) {
- char *prev = curr_message;
- if (msg)
+message_set(const char *msg)
+{
+ free(curr_message);
+
+ if (msg) {
curr_message = strdup(msg);
- else
+ message_cont = 0;
+ } else {
curr_message = NULL;
- free(prev);
+ message_cont = 1;
+ }
return NULL;
}
@@ -1361,6 +1375,22 @@ engine_loop(int countmax)
if (!averageonly ||
(averageonly && count == countmax - 1))
disp_update();
+ if (message_cont) {
+ switch (message_mode) {
+ case MESSAGE_NONE:
+ message_set(NULL);
+ break;
+ case MESSAGE_HELP:
+ show_help();
+ break;
+ case MESSAGE_VIEW:
+ show_view();
+ break;
+ case MESSAGE_ORDER:
+ show_order();
+ break;
+ }
+ }
end_page();
need_update = 0;
if (countmax && ++count >= countmax)
Index: engine.h
===================================================================
RCS file: /cvs/src/usr.bin/systat/engine.h,v
retrieving revision 1.12
diff -u -p -r1.12 engine.h
--- engine.h 12 Jan 2020 20:51:08 -0000 1.12
+++ engine.h 9 Mar 2021 18:32:24 -0000
@@ -95,6 +95,12 @@ struct command {
void ( *exec)(const char *);
};
+enum message_mode {
+ MESSAGE_NONE,
+ MESSAGE_HELP,
+ MESSAGE_VIEW,
+ MESSAGE_ORDER
+};
void tb_start(void);
@@ -133,6 +139,9 @@ void prev_view(void);
int foreach_order(void (*callback)(order_type *));
void set_order(const char *opt);
void next_order(void);
+void show_help(void);
+void show_view(void);
+void show_order(void);
void setup_term(int maxpr);
int check_termcap(void);
@@ -141,6 +150,7 @@ void engine_initialize(void);
void engine_loop(int countmax);
struct command *command_set(struct command *cmd, const char *init);
+void message_toggle(enum message_mode);
const char *message_set(const char *msg);
void foreach_view(void (*callback)(field_view *));
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/main.c,v
retrieving revision 1.73
diff -u -p -r1.73 main.c
--- main.c 30 Jan 2021 08:44:42 -0000 1.73
+++ main.c 9 Mar 2021 18:32:24 -0000
@@ -284,8 +284,7 @@ cmd_compat(const char *buf)
const char *s;
if (strcasecmp(buf, "help") == 0) {
- show_help();
- need_update = 1;
+ message_toggle(MESSAGE_HELP);
return;
}
if (strcasecmp(buf, "quit") == 0 || strcasecmp(buf, "q") == 0) {
@@ -304,8 +303,7 @@ cmd_compat(const char *buf)
return;
}
if (strncasecmp(buf, "order", 5) == 0) {
- show_order();
- need_update = 1;
+ message_toggle(MESSAGE_ORDER);
return;
}
if (strncasecmp(buf, "human", 5) == 0) {
@@ -358,12 +356,10 @@ keyboard_callback(int ch)
case '?':
/* FALLTHROUGH */
case 'h':
- show_help();
- need_update = 1;
+ message_toggle(MESSAGE_HELP);
break;
case CTRL_G:
- show_view();
- need_update = 1;
+ message_toggle(MESSAGE_VIEW);
break;
case 'l':
command_set(&cm_count, NULL);
Index: systat.1
===================================================================
RCS file: /cvs/src/usr.bin/systat/systat.1,v
retrieving revision 1.119
diff -u -p -r1.119 systat.1
--- systat.1 22 Jun 2020 13:17:54 -0000 1.119
+++ systat.1 9 Mar 2021 18:32:24 -0000
@@ -175,6 +175,8 @@ line typed as a command.
While entering a command the
current character erase, word erase, and line kill characters
may be used.
+.It Ic h
+Toggle printing the names of the available views on the command line.
.It Ic o
Select the next ordering which sorts the rows according to a
combination of columns.
@@ -201,7 +203,7 @@ Jump to the end of the current view.
.It Ic ^F | Aq Ic left arrow
Select the next view.
.It Ic ^G
-Print the name of the current
+Toggle printing the name of the current
view being shown and the refresh interval.
.It Ic ^L
Refresh the screen.
@@ -220,11 +222,11 @@ The following commands are interpreted b
command interpreter.
.Bl -tag -width Ds
.It Ic help
-Print the names of the available views on the command line.
+Toggle printing the names of the available views on the command line.
.It Ic human
Toggle human readable mode, where applicable.
.It Ic order
-Print the names of the available orderings on the command line.
+Toggle printing the names of the available orderings on the command line.
.It Ic quit
Quit
.Nm .