From e7e79d0ae675314b9abae016041874e1c221953b Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 12 Apr 2021 09:36:12 +0000 Subject: [PATCH] Add a flag to disable keys to close a message, GitHub issue 2625. --- usr.bin/tmux/alerts.c | 11 ++++++----- usr.bin/tmux/cmd-display-message.c | 12 +++++++----- usr.bin/tmux/cmd-list-keys.c | 9 +++++---- usr.bin/tmux/cmd-queue.c | 4 ++-- usr.bin/tmux/cmd-run-shell.c | 4 ++-- usr.bin/tmux/mode-tree.c | 4 ++-- usr.bin/tmux/server-client.c | 8 ++++++-- usr.bin/tmux/status.c | 9 ++++++--- usr.bin/tmux/tmux.1 | 6 ++++-- usr.bin/tmux/tmux.h | 5 +++-- usr.bin/tmux/window-customize.c | 6 +++--- 11 files changed, 46 insertions(+), 32 deletions(-) diff --git a/usr.bin/tmux/alerts.c b/usr.bin/tmux/alerts.c index 71fb3b88cea..c6d072fc693 100644 --- a/usr.bin/tmux/alerts.c +++ b/usr.bin/tmux/alerts.c @@ -1,4 +1,4 @@ -/* $OpenBSD: alerts.c,v 1.32 2020/08/19 07:15:42 nicm Exp $ */ +/* $OpenBSD: alerts.c,v 1.33 2021/04/12 09:36:12 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott @@ -315,10 +315,11 @@ alerts_set_message(struct winlink *wl, const char *type, const char *option) tty_putcode(&c->tty, TTYC_BEL); if (visual == VISUAL_OFF) continue; - if (c->session->curw == wl) - status_message_set(c, -1, 1, "%s in current window", type); - else { - status_message_set(c, -1, 1, "%s in window %d", type, + if (c->session->curw == wl) { + status_message_set(c, -1, 1, 0, "%s in current window", + type); + } else { + status_message_set(c, -1, 1, 0, "%s in window %d", type, wl->idx); } } diff --git a/usr.bin/tmux/cmd-display-message.c b/usr.bin/tmux/cmd-display-message.c index 94c1b975974..0e45a977925 100644 --- a/usr.bin/tmux/cmd-display-message.c +++ b/usr.bin/tmux/cmd-display-message.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-display-message.c,v 1.56 2021/04/07 12:49:33 nicm Exp $ */ +/* $OpenBSD: cmd-display-message.c,v 1.57 2021/04/12 09:36:12 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha @@ -39,8 +39,8 @@ const struct cmd_entry cmd_display_message_entry = { .name = "display-message", .alias = "display", - .args = { "acd:Ipt:F:v", 0, 1 }, - .usage = "[-aIpv] [-c target-client] [-d delay] [-F format] " + .args = { "acd:INpt:F:v", 0, 1 }, + .usage = "[-aINpv] [-c target-client] [-d delay] [-F format] " CMD_TARGET_PANE_USAGE " [message]", .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, @@ -132,8 +132,10 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) cmdq_error(item, "%s", msg); else if (args_has(args, 'p')) cmdq_print(item, "%s", msg); - else if (tc != NULL) - status_message_set(tc, delay, 0, "%s", msg); + else if (tc != NULL) { + status_message_set(tc, delay, 0, args_has(args, 'N'), "%s", + msg); + } free(msg); format_free(ft); diff --git a/usr.bin/tmux/cmd-list-keys.c b/usr.bin/tmux/cmd-list-keys.c index d75b76c51fb..918c2686874 100644 --- a/usr.bin/tmux/cmd-list-keys.c +++ b/usr.bin/tmux/cmd-list-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-keys.c,v 1.61 2020/07/27 08:03:10 nicm Exp $ */ +/* $OpenBSD: cmd-list-keys.c,v 1.62 2021/04/12 09:36:12 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -113,9 +113,10 @@ cmd_list_keys_print_notes(struct cmdq_item *item, struct args *args, else note = xstrdup(bd->note); tmp = utf8_padcstr(key, keywidth + 1); - if (args_has(args, '1') && tc != NULL) - status_message_set(tc, -1, 1, "%s%s%s", prefix, tmp, note); - else + if (args_has(args, '1') && tc != NULL) { + status_message_set(tc, -1, 1, 0, "%s%s%s", prefix, tmp, + note); + } else cmdq_print(item, "%s%s%s", prefix, tmp, note); free(tmp); free(note); diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c index 96d609a8405..fb968e88842 100644 --- a/usr.bin/tmux/cmd-queue.c +++ b/usr.bin/tmux/cmd-queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-queue.c,v 1.101 2021/04/07 12:50:12 nicm Exp $ */ +/* $OpenBSD: cmd-queue.c,v 1.102 2021/04/12 09:36:12 nicm Exp $ */ /* * Copyright (c) 2013 Nicholas Marriott @@ -862,7 +862,7 @@ cmdq_error(struct cmdq_item *item, const char *fmt, ...) c->retval = 1; } else { *msg = toupper((u_char) *msg); - status_message_set(c, -1, 1, "%s", msg); + status_message_set(c, -1, 1, 0, "%s", msg); } free(msg); diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c index 67e8b446905..bd6650a68bd 100644 --- a/usr.bin/tmux/cmd-run-shell.c +++ b/usr.bin/tmux/cmd-run-shell.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-run-shell.c,v 1.72 2021/03/15 13:06:33 nicm Exp $ */ +/* $OpenBSD: cmd-run-shell.c,v 1.73 2021/04/12 09:36:12 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha @@ -193,7 +193,7 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg) if (status == CMD_PARSE_ERROR) { if (cdata->item == NULL) { *error = toupper((u_char)*error); - status_message_set(c, -1, 1, "%s", error); + status_message_set(c, -1, 1, 0, "%s", error); } else cmdq_error(cdata->item, "%s", error); free(error); diff --git a/usr.bin/tmux/mode-tree.c b/usr.bin/tmux/mode-tree.c index 1d1bee611f5..5427b242c04 100644 --- a/usr.bin/tmux/mode-tree.c +++ b/usr.bin/tmux/mode-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mode-tree.c,v 1.52 2021/04/12 06:50:25 nicm Exp $ */ +/* $OpenBSD: mode-tree.c,v 1.53 2021/04/12 09:36:12 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott @@ -1204,7 +1204,7 @@ mode_tree_run_command(struct client *c, struct cmd_find_state *fs, if (status == CMD_PARSE_ERROR) { if (c != NULL) { *error = toupper((u_char)*error); - status_message_set(c, -1, 1, "%s", error); + status_message_set(c, -1, 1, 0, "%s", error); } free(error); } diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 0fc392008da..ddb09ac390f 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.371 2021/04/05 14:11:05 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.372 2021/04/12 09:36:12 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -1311,7 +1311,11 @@ server_client_handle_key(struct client *c, struct key_event *event) * immediately rather than queued. */ if (~c->flags & CLIENT_READONLY) { - status_message_clear(c); + if (c->message_string != NULL) { + if (c->message_ignore_keys) + return (0); + status_message_clear(c); + } if (c->overlay_key != NULL) { switch (c->overlay_key(c, event)) { case 0: diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 451c51376a1..f94820d4786 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.220 2021/02/22 06:53:04 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.221 2021/04/12 09:36:12 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -424,7 +424,7 @@ status_redraw(struct client *c) /* Set a status line message. */ void status_message_set(struct client *c, int delay, int ignore_styles, - const char *fmt, ...) + int ignore_keys, const char *fmt, ...) { struct timeval tv; va_list ap; @@ -433,7 +433,6 @@ status_message_set(struct client *c, int delay, int ignore_styles, status_push_screen(c); va_start(ap, fmt); - c->message_ignore_styles = ignore_styles; xvasprintf(&c->message_string, fmt, ap); va_end(ap); @@ -456,6 +455,10 @@ status_message_set(struct client *c, int delay, int ignore_styles, evtimer_add(&c->message_timer, &tv); } + if (delay != 0) + c->message_ignore_keys = ignore_keys; + c->message_ignore_styles = ignore_styles; + c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE); c->flags |= CLIENT_REDRAWSTATUS; } diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 930cbf4e2a1..f1e351467d9 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.833 2021/04/12 06:50:25 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.834 2021/04/12 09:36:12 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -5565,7 +5565,7 @@ The following keys are also available: .It Li "q" Ta "Exit menu" .El .It Xo Ic display-message -.Op Fl aIpv +.Op Fl aINpv .Op Fl c Ar target-client .Op Fl d Ar delay .Op Fl t Ar target-pane @@ -5585,6 +5585,8 @@ If is not given, the .Ic message-time option is used; a delay of zero waits for a key press. +.Ql N +ignores key presses and closes only after the delay expires. The format of .Ar message is described in the diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 8cb31798b03..42a4cef21e7 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1102 2021/04/12 06:50:25 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1103 2021/04/12 09:36:12 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1687,6 +1687,7 @@ struct client { uint64_t redraw_panes; + int message_ignore_keys; int message_ignore_styles; char *message_string; struct event message_timer; @@ -2490,7 +2491,7 @@ struct style_range *status_get_range(struct client *, u_int, u_int); void status_init(struct client *); void status_free(struct client *); int status_redraw(struct client *); -void status_message_set(struct client *, int, int, const char *, ...); +void status_message_set(struct client *, int, int, int, const char *, ...); void status_message_clear(struct client *); int status_message_redraw(struct client *); void status_prompt_set(struct client *, struct cmd_find_state *, diff --git a/usr.bin/tmux/window-customize.c b/usr.bin/tmux/window-customize.c index 6e09bc54883..37203cdb991 100644 --- a/usr.bin/tmux/window-customize.c +++ b/usr.bin/tmux/window-customize.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-customize.c,v 1.9 2021/04/12 06:50:25 nicm Exp $ */ +/* $OpenBSD: window-customize.c,v 1.10 2021/04/12 09:36:12 nicm Exp $ */ /* * Copyright (c) 2020 Nicholas Marriott @@ -999,7 +999,7 @@ window_customize_set_option_callback(struct client *c, void *itemdata, fail: *cause = toupper((u_char)*cause); - status_message_set(c, -1, 1, "%s", cause); + status_message_set(c, -1, 1, 0, "%s", cause); free(cause); return (0); } @@ -1205,7 +1205,7 @@ window_customize_set_command_callback(struct client *c, void *itemdata, fail: *error = toupper((u_char)*error); - status_message_set(c, -1, 1, "%s", error); + status_message_set(c, -1, 1, 0, "%s", error); free(error); return (0); } -- 2.20.1