From 5c89d835a60fd5957c9ff6446eab4a54d52dd7bd Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 1 Sep 2025 08:03:07 +0000 Subject: [PATCH] Add -k flag to display-popup which allows any key to dismiss the popup once the command has exited. From Meriel Luna Mittelbach in GitHub issue 4612. --- cmd-display-menu.c | 6 ++++-- popup.c | 3 +++ tmux.1 | 7 ++++++- tmux.h | 9 +++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cmd-display-menu.c b/cmd-display-menu.c index ab1b7047..bd5012f2 100644 --- a/cmd-display-menu.c +++ b/cmd-display-menu.c @@ -55,8 +55,8 @@ const struct cmd_entry cmd_display_popup_entry = { .name = "display-popup", .alias = "popup", - .args = { "Bb:Cc:d:e:Eh:s:S:t:T:w:x:y:", 0, -1, NULL }, - .usage = "[-BCE] [-b border-lines] [-c target-client] " + .args = { "Bb:Cc:d:e:Eh:ks:S:t:T:w:x:y:", 0, -1, NULL }, + .usage = "[-BCEk] [-b border-lines] [-c target-client] " "[-d start-directory] [-e environment] [-h height] " "[-s style] [-S border-style] " CMD_TARGET_PANE_USAGE " [-T title] [-w width] [-x position] [-y position] " @@ -485,6 +485,8 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) flags |= POPUP_CLOSEEXITZERO; else if (args_has(args, 'E')) flags |= POPUP_CLOSEEXIT; + if (args_has(args, 'k')) + flags |= POPUP_CLOSEANYKEY; if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc, argv, cwd, title, tc, s, style, border_style, NULL, NULL) != 0) { cmd_free_argv(argc, argv); diff --git a/popup.c b/popup.c index 138085a0..619a32ce 100644 --- a/popup.c +++ b/popup.c @@ -549,6 +549,9 @@ popup_key_cb(struct client *c, void *data, struct key_event *event) pd->job == NULL) && (event->key == '\033' || event->key == ('c'|KEYC_CTRL))) return (1); + if (pd->job == NULL && (pd->flags & POPUP_CLOSEANYKEY) && + !KEYC_IS_MOUSE(event->key) && !KEYC_IS_PASTE(event->key)) + return (1); if (pd->job != NULL) { if (KEYC_IS_MOUSE(event->key)) { /* Must be inside, checked already. */ diff --git a/tmux.1 b/tmux.1 index f7ea02d8..73c4ad9d 100644 --- a/tmux.1 +++ b/tmux.1 @@ -6967,7 +6967,7 @@ forwards any input read from stdin to the empty pane given by .Ar target-pane . .Tg popup .It Xo Ic display-popup -.Op Fl BCE +.Op Fl BCEk .Op Fl b Ar border-lines .Op Fl c Ar target-client .Op Fl d Ar start-directory @@ -7001,6 +7001,11 @@ Two closes the popup only if .Ar shell-command exited with success. +.Fl k +allows any key to dismiss the popup instead of only +.Ql Escape +or +.Ql C-c . .Pp .Fl x and diff --git a/tmux.h b/tmux.h index 84821746..02d8d1fb 100644 --- a/tmux.h +++ b/tmux.h @@ -1543,10 +1543,10 @@ struct tty { #define TTY_SYNCING 0x400 #define TTY_HAVEDA2 0x800 #define TTY_WINSIZEQUERY 0x1000 -#define TTY_HAVEFG 0x2000 -#define TTY_HAVEBG 0x4000 +#define TTY_WAITFG 0x2000 +#define TTY_WAITBG 0x4000 #define TTY_ALL_REQUEST_FLAGS \ - (TTY_HAVEDA|TTY_HAVEDA2|TTY_HAVEXDA|TTY_HAVEFG|TTY_HAVEBG) + (TTY_HAVEDA|TTY_HAVEDA2|TTY_HAVEXDA) int flags; struct tty_term *term; @@ -2474,7 +2474,7 @@ void tty_set_size(struct tty *, u_int, u_int, u_int, u_int); void tty_invalidate(struct tty *); void tty_start_tty(struct tty *); void tty_send_requests(struct tty *); -void tty_repeat_requests(struct tty *); +void tty_repeat_requests(struct tty *, int); void tty_stop_tty(struct tty *); void tty_set_title(struct tty *, const char *); void tty_set_path(struct tty *, const char *); @@ -3523,6 +3523,7 @@ int menu_key_cb(struct client *, void *, struct key_event *); #define POPUP_CLOSEEXIT 0x1 #define POPUP_CLOSEEXITZERO 0x2 #define POPUP_INTERNAL 0x4 +#define POPUP_CLOSEANYKEY 0x8 typedef void (*popup_close_cb)(int, void *); typedef void (*popup_finish_edit_cb)(char *, size_t, void *); int popup_display(int, enum box_lines, struct cmdq_item *, u_int,