diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-10-04 19:16:14 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-10-04 19:16:14 +0000 |
commit | f20a66161733e61bfcbd230634a05d6616b1b18b (patch) | |
tree | 0390c3e384e720d6ee77be70d2c075b6dd90abb6 | |
parent | 70c4fcf349c5a844d14fad5bc9d1039d4cb5e263 (diff) |
Add -y flag to disable confirmation prompts in modes, GitHub issue 4152.
-rw-r--r-- | usr.bin/tmux/cmd-choose-tree.c | 10 | ||||
-rw-r--r-- | usr.bin/tmux/status.c | 18 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 14 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 | ||||
-rw-r--r-- | usr.bin/tmux/window-customize.c | 17 | ||||
-rw-r--r-- | usr.bin/tmux/window-tree.c | 11 |
6 files changed, 54 insertions, 19 deletions
diff --git a/usr.bin/tmux/cmd-choose-tree.c b/usr.bin/tmux/cmd-choose-tree.c index 59a63718dcd..dfd5c8add2d 100644 --- a/usr.bin/tmux/cmd-choose-tree.c +++ b/usr.bin/tmux/cmd-choose-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-choose-tree.c,v 1.51 2022/06/04 07:42:07 nicm Exp $ */ +/* $OpenBSD: cmd-choose-tree.c,v 1.52 2024/10/04 19:16:13 nicm Exp $ */ /* * Copyright (c) 2012 Thomas Adam <thomas@xteddy.org> @@ -33,7 +33,7 @@ const struct cmd_entry cmd_choose_tree_entry = { .name = "choose-tree", .alias = NULL, - .args = { "F:f:GK:NO:rst:wZ", 0, 1, cmd_choose_tree_args_parse }, + .args = { "F:f:GK:NO:rst:wyZ", 0, 1, cmd_choose_tree_args_parse }, .usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] " "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]", @@ -47,7 +47,7 @@ const struct cmd_entry cmd_choose_client_entry = { .name = "choose-client", .alias = NULL, - .args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse }, + .args = { "F:f:K:NO:rt:yZ", 0, 1, cmd_choose_tree_args_parse }, .usage = "[-NrZ] [-F format] [-f filter] [-K key-format] " "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]", @@ -61,7 +61,7 @@ const struct cmd_entry cmd_choose_buffer_entry = { .name = "choose-buffer", .alias = NULL, - .args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse }, + .args = { "F:f:K:NO:rt:yZ", 0, 1, cmd_choose_tree_args_parse }, .usage = "[-NrZ] [-F format] [-f filter] [-K key-format] " "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]", @@ -75,7 +75,7 @@ const struct cmd_entry cmd_customize_mode_entry = { .name = "customize-mode", .alias = NULL, - .args = { "F:f:Nt:Z", 0, 0, NULL }, + .args = { "F:f:Nt:yZ", 0, 0, NULL }, .usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE, .target = { 't', CMD_FIND_PANE, 0 }, diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index ad7208ef181..65a5f84ddd2 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.245 2024/08/22 09:05:51 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.246 2024/10/04 19:16:13 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -598,6 +598,19 @@ status_message_redraw(struct client *c) return (1); } +/* Accept prompt immediately. */ +static enum cmd_retval +status_prompt_accept(__unused struct cmdq_item *item, void *data) +{ + struct client *c = data; + + if (c->prompt_string != NULL) { + c->prompt_inputcb(c, c->prompt_data, "y", 1); + status_prompt_clear(c); + } + return (CMD_RETURN_NORMAL); +} + /* Enable status line prompt. */ void status_prompt_set(struct client *c, struct cmd_find_state *fs, @@ -655,6 +668,9 @@ status_prompt_set(struct client *c, struct cmd_find_state *fs, free(tmp); format_free(ft); + + if ((flags & PROMPT_SINGLE) && (flags & PROMPT_ACCEPT)) + cmdq_append(c, cmdq_get_callback(status_prompt_accept, c)); } /* Remove status line prompt. */ diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 8538ca6af33..18cd7a8c965 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.959 2024/10/04 07:03:08 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.960 2024/10/04 19:16:13 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -2581,7 +2581,7 @@ the end of the visible pane. The default is to capture only the visible contents of the pane. .It Xo .Ic choose-client -.Op Fl NrZ +.Op Fl NryZ .Op Fl F Ar format .Op Fl f Ar filter .Op Fl K Ar key-format @@ -2597,6 +2597,8 @@ or the list may be navigated and an item chosen or otherwise manipulated using the keys below. .Fl Z zooms the pane. +.Fl y +disables any confirmation prompts. The following keys may be used in client mode: .Bl -column "Key" "Function" -offset indent .It Sy "Key" Ta Sy "Function" @@ -2655,7 +2657,7 @@ starts without the preview or if given twice with the larger preview. This command works only if at least one client is attached. .It Xo .Ic choose-tree -.Op Fl GNrswZ +.Op Fl GNrswyZ .Op Fl F Ar format .Op Fl f Ar filter .Op Fl K Ar key-format @@ -2675,6 +2677,8 @@ starts with sessions collapsed and with windows collapsed. .Fl Z zooms the pane. +.Fl y +disables any confirmation prompts. The following keys may be used in tree mode: .Bl -column "Key" "Function" -offset indent .It Sy "Key" Ta Sy "Function" @@ -6807,7 +6811,7 @@ The buffer commands are as follows: .Bl -tag -width Ds .It Xo .Ic choose-buffer -.Op Fl NZr +.Op Fl NryZ .Op Fl F Ar format .Op Fl f Ar filter .Op Fl K Ar key-format @@ -6823,6 +6827,8 @@ or the list may be navigated and an item chosen or otherwise manipulated using the keys below. .Fl Z zooms the pane. +.Fl y +disables any confirmation prompts. The following keys may be used in buffer mode: .Bl -column "Key" "Function" -offset indent .It Sy "Key" Ta Sy "Function" diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index e904e8e80f6..f8b52b2788a 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1232 2024/10/02 11:48:16 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1233 2024/10/04 19:16:13 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1935,6 +1935,7 @@ struct client { #define PROMPT_INCREMENTAL 0x4 #define PROMPT_NOFORMAT 0x8 #define PROMPT_KEY 0x10 +#define PROMPT_ACCEPT 0x20 int prompt_flags; enum prompt_type prompt_type; int prompt_cursor; diff --git a/usr.bin/tmux/window-customize.c b/usr.bin/tmux/window-customize.c index cc5dbd5528f..5cd6fc6ad0a 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.14 2022/03/24 12:07:25 nicm Exp $ */ +/* $OpenBSD: window-customize.c,v 1.15 2024/10/04 19:16:13 nicm Exp $ */ /* * Copyright (c) 2020 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -101,6 +101,7 @@ struct window_customize_modedata { struct mode_tree_data *data; char *format; int hide_global; + int prompt_flags; struct window_customize_itemdata **item_list; u_int item_size; @@ -885,6 +886,8 @@ window_customize_init(struct window_mode_entry *wme, struct cmd_find_state *fs, data->format = xstrdup(WINDOW_CUSTOMIZE_DEFAULT_FORMAT); else data->format = xstrdup(args_get(args, 'F')); + if (args_has(args, 'y')) + data->prompt_flags = PROMPT_ACCEPT; data->data = mode_tree_start(wp, args, window_customize_build, window_customize_draw, NULL, window_customize_menu, @@ -1453,7 +1456,8 @@ window_customize_key(struct window_mode_entry *wme, struct client *c, status_prompt_set(c, NULL, prompt, "", window_customize_change_current_callback, window_customize_free_callback, data, - PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND); + PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags, + PROMPT_TYPE_COMMAND); free(prompt); break; case 'D': @@ -1466,7 +1470,8 @@ window_customize_key(struct window_mode_entry *wme, struct client *c, status_prompt_set(c, NULL, prompt, "", window_customize_change_tagged_callback, window_customize_free_callback, data, - PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND); + PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags, + PROMPT_TYPE_COMMAND); free(prompt); break; case 'u': @@ -1482,7 +1487,8 @@ window_customize_key(struct window_mode_entry *wme, struct client *c, status_prompt_set(c, NULL, prompt, "", window_customize_change_current_callback, window_customize_free_callback, data, - PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND); + PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags, + PROMPT_TYPE_COMMAND); free(prompt); break; case 'U': @@ -1495,7 +1501,8 @@ window_customize_key(struct window_mode_entry *wme, struct client *c, status_prompt_set(c, NULL, prompt, "", window_customize_change_tagged_callback, window_customize_free_callback, data, - PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND); + PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags, + PROMPT_TYPE_COMMAND); free(prompt); break; case 'H': diff --git a/usr.bin/tmux/window-tree.c b/usr.bin/tmux/window-tree.c index 6af8326429f..ba4f40aaa59 100644 --- a/usr.bin/tmux/window-tree.c +++ b/usr.bin/tmux/window-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-tree.c,v 1.63 2023/06/30 21:55:09 nicm Exp $ */ +/* $OpenBSD: window-tree.c,v 1.64 2024/10/04 19:16:13 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -131,6 +131,7 @@ struct window_tree_modedata { char *key_format; char *command; int squash_groups; + int prompt_flags; struct window_tree_itemdata **item_list; u_int item_size; @@ -934,6 +935,8 @@ window_tree_init(struct window_mode_entry *wme, struct cmd_find_state *fs, else data->command = xstrdup(args_string(args, 0)); data->squash_groups = !args_has(args, 'G'); + if (args_has(args, 'y')) + data->prompt_flags = PROMPT_ACCEPT; data->data = mode_tree_start(wp, args, window_tree_build, window_tree_draw, window_tree_search, window_tree_menu, NULL, @@ -1305,7 +1308,8 @@ again: data->references++; status_prompt_set(c, NULL, prompt, "", window_tree_kill_current_callback, window_tree_command_free, - data, PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND); + data, PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags, + PROMPT_TYPE_COMMAND); free(prompt); break; case 'X': @@ -1316,7 +1320,8 @@ again: data->references++; status_prompt_set(c, NULL, prompt, "", window_tree_kill_tagged_callback, window_tree_command_free, - data, PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND); + data, PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags, + PROMPT_TYPE_COMMAND); free(prompt); break; case ':': |