Add a flag to disable keys to close a message, GitHub issue 2625.

This commit is contained in:
nicm 2021-04-12 09:36:12 +00:00
parent cd208c9d72
commit e6abe55134
11 changed files with 35 additions and 21 deletions

View File

@ -315,10 +315,11 @@ alerts_set_message(struct winlink *wl, const char *type, const char *option)
tty_putcode(&c->tty, TTYC_BEL); tty_putcode(&c->tty, TTYC_BEL);
if (visual == VISUAL_OFF) if (visual == VISUAL_OFF)
continue; continue;
if (c->session->curw == wl) if (c->session->curw == wl) {
status_message_set(c, -1, 1, "%s in current window", type); status_message_set(c, -1, 1, 0, "%s in current window",
else { type);
status_message_set(c, -1, 1, "%s in window %d", type, } else {
status_message_set(c, -1, 1, 0, "%s in window %d", type,
wl->idx); wl->idx);
} }
} }

View File

@ -39,8 +39,8 @@ const struct cmd_entry cmd_display_message_entry = {
.name = "display-message", .name = "display-message",
.alias = "display", .alias = "display",
.args = { "acd:Ipt:F:v", 0, 1 }, .args = { "acd:INpt:F:v", 0, 1 },
.usage = "[-aIpv] [-c target-client] [-d delay] [-F format] " .usage = "[-aINpv] [-c target-client] [-d delay] [-F format] "
CMD_TARGET_PANE_USAGE " [message]", CMD_TARGET_PANE_USAGE " [message]",
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, .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); cmdq_error(item, "%s", msg);
else if (args_has(args, 'p')) else if (args_has(args, 'p'))
cmdq_print(item, "%s", msg); cmdq_print(item, "%s", msg);
else if (tc != NULL) else if (tc != NULL) {
status_message_set(tc, delay, 0, "%s", msg); status_message_set(tc, delay, 0, args_has(args, 'N'), "%s",
msg);
}
free(msg); free(msg);
format_free(ft); format_free(ft);

View File

@ -113,9 +113,10 @@ cmd_list_keys_print_notes(struct cmdq_item *item, struct args *args,
else else
note = xstrdup(bd->note); note = xstrdup(bd->note);
tmp = utf8_padcstr(key, keywidth + 1); tmp = utf8_padcstr(key, keywidth + 1);
if (args_has(args, '1') && tc != NULL) if (args_has(args, '1') && tc != NULL) {
status_message_set(tc, -1, 1, "%s%s%s", prefix, tmp, note); status_message_set(tc, -1, 1, 0, "%s%s%s", prefix, tmp,
else note);
} else
cmdq_print(item, "%s%s%s", prefix, tmp, note); cmdq_print(item, "%s%s%s", prefix, tmp, note);
free(tmp); free(tmp);
free(note); free(note);

View File

@ -862,7 +862,7 @@ cmdq_error(struct cmdq_item *item, const char *fmt, ...)
c->retval = 1; c->retval = 1;
} else { } else {
*msg = toupper((u_char) *msg); *msg = toupper((u_char) *msg);
status_message_set(c, -1, 1, "%s", msg); status_message_set(c, -1, 1, 0, "%s", msg);
} }
free(msg); free(msg);

View File

@ -193,7 +193,7 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg)
if (status == CMD_PARSE_ERROR) { if (status == CMD_PARSE_ERROR) {
if (cdata->item == NULL) { if (cdata->item == NULL) {
*error = toupper((u_char)*error); *error = toupper((u_char)*error);
status_message_set(c, -1, 1, "%s", error); status_message_set(c, -1, 1, 0, "%s", error);
} else } else
cmdq_error(cdata->item, "%s", error); cmdq_error(cdata->item, "%s", error);
free(error); free(error);

View File

@ -1204,7 +1204,7 @@ mode_tree_run_command(struct client *c, struct cmd_find_state *fs,
if (status == CMD_PARSE_ERROR) { if (status == CMD_PARSE_ERROR) {
if (c != NULL) { if (c != NULL) {
*error = toupper((u_char)*error); *error = toupper((u_char)*error);
status_message_set(c, -1, 1, "%s", error); status_message_set(c, -1, 1, 0, "%s", error);
} }
free(error); free(error);
} }

View File

@ -1311,7 +1311,11 @@ server_client_handle_key(struct client *c, struct key_event *event)
* immediately rather than queued. * immediately rather than queued.
*/ */
if (~c->flags & CLIENT_READONLY) { 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) { if (c->overlay_key != NULL) {
switch (c->overlay_key(c, event)) { switch (c->overlay_key(c, event)) {
case 0: case 0:

View File

@ -424,7 +424,7 @@ status_redraw(struct client *c)
/* Set a status line message. */ /* Set a status line message. */
void void
status_message_set(struct client *c, int delay, int ignore_styles, status_message_set(struct client *c, int delay, int ignore_styles,
const char *fmt, ...) int ignore_keys, const char *fmt, ...)
{ {
struct timeval tv; struct timeval tv;
va_list ap; va_list ap;
@ -433,7 +433,6 @@ status_message_set(struct client *c, int delay, int ignore_styles,
status_push_screen(c); status_push_screen(c);
va_start(ap, fmt); va_start(ap, fmt);
c->message_ignore_styles = ignore_styles;
xvasprintf(&c->message_string, fmt, ap); xvasprintf(&c->message_string, fmt, ap);
va_end(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); 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->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE);
c->flags |= CLIENT_REDRAWSTATUS; c->flags |= CLIENT_REDRAWSTATUS;
} }

4
tmux.1
View File

@ -5565,7 +5565,7 @@ The following keys are also available:
.It Li "q" Ta "Exit menu" .It Li "q" Ta "Exit menu"
.El .El
.It Xo Ic display-message .It Xo Ic display-message
.Op Fl aIpv .Op Fl aINpv
.Op Fl c Ar target-client .Op Fl c Ar target-client
.Op Fl d Ar delay .Op Fl d Ar delay
.Op Fl t Ar target-pane .Op Fl t Ar target-pane
@ -5585,6 +5585,8 @@ If
is not given, the is not given, the
.Ic message-time .Ic message-time
option is used; a delay of zero waits for a key press. 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 The format of
.Ar message .Ar message
is described in the is described in the

3
tmux.h
View File

@ -1687,6 +1687,7 @@ struct client {
uint64_t redraw_panes; uint64_t redraw_panes;
int message_ignore_keys;
int message_ignore_styles; int message_ignore_styles;
char *message_string; char *message_string;
struct event message_timer; 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_init(struct client *);
void status_free(struct client *); void status_free(struct client *);
int status_redraw(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 *); void status_message_clear(struct client *);
int status_message_redraw(struct client *); int status_message_redraw(struct client *);
void status_prompt_set(struct client *, struct cmd_find_state *, void status_prompt_set(struct client *, struct cmd_find_state *,

View File

@ -999,7 +999,7 @@ window_customize_set_option_callback(struct client *c, void *itemdata,
fail: fail:
*cause = toupper((u_char)*cause); *cause = toupper((u_char)*cause);
status_message_set(c, -1, 1, "%s", cause); status_message_set(c, -1, 1, 0, "%s", cause);
free(cause); free(cause);
return (0); return (0);
} }
@ -1205,7 +1205,7 @@ window_customize_set_command_callback(struct client *c, void *itemdata,
fail: fail:
*error = toupper((u_char)*error); *error = toupper((u_char)*error);
status_message_set(c, -1, 1, "%s", error); status_message_set(c, -1, 1, 0, "%s", error);
free(error); free(error);
return (0); return (0);
} }