From d539d1dae58d5bfb1ac74785c2ca22c2e90c984c Mon Sep 17 00:00:00 2001 From: martijn Date: Wed, 2 Jun 2021 08:32:22 +0000 Subject: [PATCH] Make the hints at the bottom row sticky by turning the knobs toggles. Specifically this effects ^G, help and order. While here also document the 'h' character. Initial inspiration and diff from Anindya Mukherjee (anindya49 hotmail com) OK bluhm@ --- usr.bin/systat/engine.c | 42 +++++++++++++++++++++++++++++++++++------ usr.bin/systat/engine.h | 12 +++++++++++- usr.bin/systat/main.c | 14 +++++--------- usr.bin/systat/systat.1 | 12 +++++++----- 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/usr.bin/systat/engine.c b/usr.bin/systat/engine.c index 2a73f25c462..068174a74cc 100644 --- a/usr.bin/systat/engine.c +++ b/usr.bin/systat/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.27 2021/02/06 06:19:28 tb Exp $ */ +/* $OpenBSD: engine.c,v 1.28 2021/06/02 08:32:22 martijn Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar * @@ -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 char *init) 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) diff --git a/usr.bin/systat/engine.h b/usr.bin/systat/engine.h index 543d665783c..c8239b5bfbd 100644 --- a/usr.bin/systat/engine.h +++ b/usr.bin/systat/engine.h @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.h,v 1.12 2020/01/12 20:51:08 martijn Exp $ */ +/* $OpenBSD: engine.h,v 1.13 2021/06/02 08:32:22 martijn Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar * @@ -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 *)); diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c index 31092ec3f9a..1a67a23e3b8 100644 --- a/usr.bin/systat/main.c +++ b/usr.bin/systat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.73 2021/01/30 08:44:42 martijn Exp $ */ +/* $OpenBSD: main.c,v 1.74 2021/06/02 08:32:22 martijn Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar * Copyright (c) 2001 Daniel Hartmeier @@ -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); diff --git a/usr.bin/systat/systat.1 b/usr.bin/systat/systat.1 index fd983f0174e..b796be1b146 100644 --- a/usr.bin/systat/systat.1 +++ b/usr.bin/systat/systat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: systat.1,v 1.119 2020/06/22 13:17:54 kn Exp $ +.\" $OpenBSD: systat.1,v 1.120 2021/06/02 08:32:22 martijn Exp $ .\" $NetBSD: systat.1,v 1.6 1996/05/10 23:16:39 thorpej Exp $ .\" .\" Copyright (c) 1985, 1990, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)systat.1 8.2 (Berkeley) 12/30/93 .\" -.Dd $Mdocdate: June 22 2020 $ +.Dd $Mdocdate: June 2 2021 $ .Dt SYSTAT 1 .Os .Sh NAME @@ -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 by the 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 . -- 2.20.1