summaryrefslogtreecommitdiffstats
path: root/cmd-display-menu.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 03:34:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 03:34:56 +0000
commit671f456761fc66649260e831ceee36ec3d4ba9ca (patch)
tree033c56bded071f681e1304311ba0bff449d477cc /cmd-display-menu.c
parentAdding debian version 3.3a-5. (diff)
downloadtmux-671f456761fc66649260e831ceee36ec3d4ba9ca.tar.xz
tmux-671f456761fc66649260e831ceee36ec3d4ba9ca.zip
Merging upstream version 3.4.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cmd-display-menu.c')
-rw-r--r--cmd-display-menu.c55
1 files changed, 46 insertions, 9 deletions
diff --git a/cmd-display-menu.c b/cmd-display-menu.c
index e6a503b..d04a17c 100644
--- a/cmd-display-menu.c
+++ b/cmd-display-menu.c
@@ -38,8 +38,10 @@ const struct cmd_entry cmd_display_menu_entry = {
.name = "display-menu",
.alias = "menu",
- .args = { "c:t:OT:x:y:", 1, -1, cmd_display_menu_args_parse },
- .usage = "[-O] [-c target-client] " CMD_TARGET_PANE_USAGE " [-T title] "
+ .args = { "b:c:C:H:s:S:Ot:T:x:y:", 1, -1, cmd_display_menu_args_parse },
+ .usage = "[-O] [-b border-lines] [-c target-client] "
+ "[-C starting-choice] [-H selected-style] [-s style] "
+ "[-S border-style] " CMD_TARGET_PANE_USAGE "[-T title] "
"[-x position] [-y position] name key command ...",
.target = { 't', CMD_FIND_PANE, 0 },
@@ -274,6 +276,7 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
log_debug("%s: -y: %s = %s = %u (-h %u)", __func__, yp, p, *py, h);
free(p);
+ format_free(ft);
return (1);
}
@@ -286,19 +289,41 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
struct client *tc = cmdq_get_target_client(item);
struct menu *menu = NULL;
struct menu_item menu_item;
- const char *key, *name;
- char *title;
- int flags = 0;
+ const char *key, *name, *value;
+ const char *style = args_get(args, 's');
+ const char *border_style = args_get(args, 'S');
+ const char *selected_style = args_get(args, 'H');
+ enum box_lines lines = BOX_LINES_DEFAULT;
+ char *title, *cause;
+ int flags = 0, starting_choice = 0;
u_int px, py, i, count = args_count(args);
+ struct options *o = target->s->curw->window->options;
+ struct options_entry *oe;
+
if (tc->overlay_draw != NULL)
return (CMD_RETURN_NORMAL);
+ if (args_has(args, 'C')) {
+ if (strcmp(args_get(args, 'C'), "-") == 0)
+ starting_choice = -1;
+ else {
+ starting_choice = args_strtonum(args, 'C', 0, UINT_MAX,
+ &cause);
+ if (cause != NULL) {
+ cmdq_error(item, "starting choice %s", cause);
+ free(cause);
+ return (CMD_RETURN_ERROR);
+ }
+ }
+ }
+
if (args_has(args, 'T'))
title = format_single_from_target(item, args_get(args, 'T'));
else
title = xstrdup("");
menu = menu_create(title);
+ free(title);
for (i = 0; i != count; /* nothing */) {
name = args_string(args, i++);
@@ -309,7 +334,6 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
if (count - i < 2) {
cmdq_error(item, "not enough arguments");
- free(title);
menu_free(menu);
return (CMD_RETURN_ERROR);
}
@@ -321,7 +345,6 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
menu_add_item(menu, &menu_item, item, tc, target);
}
- free(title);
if (menu == NULL) {
cmdq_error(item, "invalid menu arguments");
return (CMD_RETURN_ERROR);
@@ -336,12 +359,24 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL);
}
+ value = args_get(args, 'b');
+ if (value != NULL) {
+ oe = options_get(o, "menu-border-lines");
+ lines = options_find_choice(options_table_entry(oe), value,
+ &cause);
+ if (lines == -1) {
+ cmdq_error(item, "menu-border-lines %s", cause);
+ free(cause);
+ return (CMD_RETURN_ERROR);
+ }
+ }
+
if (args_has(args, 'O'))
flags |= MENU_STAYOPEN;
if (!event->m.valid)
flags |= MENU_NOMOUSE;
- if (menu_display(menu, flags, item, px, py, tc, target, NULL,
- NULL) != 0)
+ if (menu_display(menu, flags, starting_choice, item, px, py, tc, lines,
+ style, selected_style, border_style, target, NULL, NULL) != 0)
return (CMD_RETURN_NORMAL);
return (CMD_RETURN_WAIT);
}
@@ -454,11 +489,13 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
cmd_free_argv(argc, argv);
if (env != NULL)
environ_free(env);
+ free(cwd);
free(title);
return (CMD_RETURN_NORMAL);
}
if (env != NULL)
environ_free(env);
+ free(cwd);
free(title);
cmd_free_argv(argc, argv);
return (CMD_RETURN_WAIT);