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    5 Mar 2021 02:35:36 -0000
@@ -70,6 +70,8 @@ volatile sig_atomic_t gotsig_alarm = 0;
 int need_update = 0;
 int need_sort = 0;
 int separate_thousands = 0;
+enum sticky_mode sticky_mode = STICKY_NONE;
+int sticky = 0;
 
 SCREEN *screen;
 
@@ -1139,7 +1141,15 @@ command_set(struct command *cmd, const c
                        cmdbuf[0] = 0;
                }
        }
-       message_set(NULL);
+
+       if (curr_message != NULL) {
+               if (!sticky) {
+                       message_set(NULL);
+                       sticky_mode = STICKY_NONE;
+               } else if (sticky_mode == STICKY_NONE)
+                       message_set(NULL);
+       }
+
        curr_cmd = cmd;
        need_update = 1;
        return prev;
@@ -1165,7 +1175,10 @@ print_cmdline(void)
                attroff(A_STANDOUT);
                printw("%s", cmdbuf);
        } else if (curr_message) {
-               mvprintw(home_line, 0, "> %s", curr_message);
+               if (sticky)
+                       mvprintw(home_line, 0, "*> %s", curr_message);
+               else
+                       mvprintw(home_line, 0, "> %s", curr_message);
        }
        clrtoeol();
 }
@@ -1233,8 +1246,12 @@ keyboard(void)
                        if (curr_mgr->key_fn(ch))
                                return;
 
-       if (curr_message != NULL) {
-               if (ch > 0) {
+       if (curr_message != NULL && ch > 0) {
+               if (!sticky) {
+                       message_set(NULL);
+                       sticky_mode = STICKY_NONE;
+                       need_update = 1;
+               } else if (sticky_mode == STICKY_NONE) {
                        message_set(NULL);
                        need_update = 1;
                }
@@ -1359,8 +1376,24 @@ engine_loop(int countmax)
                if (need_update) {
                        erase();
                        if (!averageonly ||
-                           (averageonly && count == countmax - 1))
+                           (averageonly && count == countmax - 1)) {
                                disp_update();
+                               if (interactive && sticky) {
+                                       switch (sticky_mode) {
+                                       case STICKY_NONE:
+                                               break;
+                                       case STICKY_HELP:
+                                               show_help();
+                                               break;
+                                       case STICKY_VIEW:
+                                               show_view();
+                                               break;
+                                       case STICKY_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    5 Mar 2021 02:35:36 -0000
@@ -36,6 +36,7 @@
 #define CTRL_L  12
 #define CTRL_N  14
 #define CTRL_P  16
+#define CTRL_T  20
 #define CTRL_V  22
 
 #define META_V  246
@@ -95,9 +96,9 @@ struct command {
        void ( *exec)(const char *);
 };
 
+enum sticky_mode {STICKY_NONE, STICKY_HELP, STICKY_VIEW, STICKY_ORDER};
 
 void tb_start(void);
-
 void tb_end(void);
 
 int tbprintf(char *format, ...) GCC_PRINTFLIKE(1,2);
@@ -144,6 +145,9 @@ struct command *command_set(struct comma
 const char *message_set(const char *msg);
 
 void foreach_view(void (*callback)(field_view *));
+void show_help(void);
+void show_view(void);
+void show_order(void);
 
 extern int sortdir;
 extern useconds_t udelay;
@@ -160,6 +164,9 @@ extern int columns, lines;
 extern int need_update;
 extern int need_sort;
 extern int separate_thousands;
+extern enum sticky_mode sticky_mode;
+extern int sticky;
+extern char *curr_message;
 
 extern volatile sig_atomic_t gotsig_close;
 extern volatile sig_atomic_t gotsig_resize;
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      5 Mar 2021 02:35:36 -0000
@@ -150,6 +150,7 @@ error(const char *fmt, ...)
        va_end(ap);
 
        message_set(buf);
+       sticky_mode = STICKY_NONE;
 }
 
 void
@@ -285,6 +286,7 @@ cmd_compat(const char *buf)
 
        if (strcasecmp(buf, "help") == 0) {
                show_help();
+               sticky_mode = STICKY_HELP;
                need_update = 1;
                return;
        }
@@ -305,6 +307,7 @@ cmd_compat(const char *buf)
        }
        if (strncasecmp(buf, "order", 5) == 0) {
                show_order();
+               sticky_mode = STICKY_ORDER;
                need_update = 1;
                return;
        }
@@ -359,11 +362,27 @@ keyboard_callback(int ch)
                /* FALLTHROUGH */
        case 'h':
                show_help();
+               sticky_mode = STICKY_HELP;
                need_update = 1;
                break;
        case CTRL_G:
                show_view();
+               sticky_mode = STICKY_VIEW;
                need_update = 1;
+               break;
+       case CTRL_T:
+               if (sticky) {
+                       sticky = 0;
+                       sticky_mode = STICKY_NONE;
+                       message_set("sticky off");
+                       need_update = 1;
+               } else {
+                       sticky = 1;
+                       if (curr_message == NULL ||
+                           strcmp(curr_message, "sticky off") == 0)
+                               message_set("sticky on");
+                       need_update = 1;
+               }
                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    5 Mar 2021 02:35:36 -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
+Print 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.
@@ -209,6 +211,11 @@ Refresh the screen.
 Scroll current view down by one line.
 .It Ic ^P | Aq Ic up arrow
 Scroll current view up by one line.
+.It Ic ^T
+Toggle sticky mode. When active, the status line display is
+not cleared on a key press while showing the available views,
+the current view, or the available orderings. The status
+line displays an asterisk in sticky mode when it is not empty.
 .It Ic ^V | Aq Ic Page Down
 Scroll current view down by one page.
 .It Ic Alt-V | Aq Ic Page Up

On Mon, Mar 01, 2021 at 08:37:58AM +0100, Martijn van Duren wrote:
> On Sun, 2021-02-28 at 23:03 -0800, Anindya Mukherjee wrote:
> > Hi,
> > 
> > Thanks for the feedback. I see your point. Perhaps it would be better to
> > have a separate "stickiness" toggle and not tie it to the help or the
> > view name display functions. For example, pressing 't' could toggle it
> > on and then pressing 'h' or Ctrl-G would make the display stick.
> > Pressing 't' again would toggle it off, and then the display would get
> > cleared normally.
> 
> Something like that seems better, but keep in mind that the single key
> bindings within systat is a mess: 't' might already be allocated by one
> of the views. When submitting your followup, try to make sure that you
> considered all possible issues, including the keybindings, and show
> how you came to your conclusion.
> > 
> > Regards,
> > Anindya
> > 
> > On Mon, Mar 01, 2021 at 07:49:49AM +0100, Martijn van Duren wrote:
> > > Although the feature *might* be useful (just woken up, so haven't given
> > > it too much thought), the bindings have some problems and need to be
> > > reworked if we decide to get this in. Problems that I see from just a
> > > few short tests (so there might be others):
> > > - Entering sticky: H, which also enters help, which is annoying if I
> > >   want sticky ^G.
> > > - Clearing sticky: h, which also displays help, which if I come from
> > >   ^G is not what I want and if I'm in help is confusing, because I want
> > >   to get rid of it.
> > > 
> > > martijn@
> > > 
> > > On Sun, 2021-02-28 at 19:40 -0800, Anindya Mukherjee wrote:
> > > > Hi,
> > > > 
> > > > I tend to keep systat(1) running in interactive mode, and find it very
> > > > useful to have the help line displayed permanently, i.e., not disappear
> > > > if a key is pressed or after a command is executed. The same goes for
> > > > the Ctrl-G display. For example, it tells me what modes are adjacent to
> > > > the currently active one when pressing left or right arrow keys.
> > > > 
> > > > The attached diff adds this feature. It is off by default. I noticed
> > > > that the 'h' key was not documented in the man page, so I took the
> > > > liberty of adding a line describing it.
> > > > 
> > > > Hope it is useful. Please have a look, thanks!
> > > > 
> > > > Regards,
> > > > Anindya
> > > > 

Reply via email to