summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd-display-menu.c29
-rw-r--r--menu.c57
-rw-r--r--mode-tree.c4
-rw-r--r--popup.c2
-rw-r--r--status.c4
-rw-r--r--tmux.14
-rw-r--r--tmux.h8
7 files changed, 74 insertions, 34 deletions
diff --git a/cmd-display-menu.c b/cmd-display-menu.c
index 6ecfad29..deff4907 100644
--- a/cmd-display-menu.c
+++ b/cmd-display-menu.c
@@ -39,9 +39,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] "
- "[-x position] [-y position] name key command ...",
+ .args = { "c:t:S:OT:x:y:", 1, -1, cmd_display_menu_args_parse },
+ .usage = "[-O] [-c target-client] [-S starting-choice] "
+ CMD_TARGET_PANE_USAGE " [-T title] [-x position] "
+ "[-y position] name key command ...",
.target = { 't', CMD_FIND_PANE, 0 },
@@ -288,13 +289,27 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
struct menu *menu = NULL;
struct menu_item menu_item;
const char *key, *name;
- char *title;
- int flags = 0;
+ char *title, *cause;
+ int flags = 0, starting_choice = 0;
u_int px, py, i, count = args_count(args);
if (tc->overlay_draw != NULL)
return (CMD_RETURN_NORMAL);
+ if (args_has(args, 'S')) {
+ if (strcmp(args_get(args, 'S'), "-") == 0)
+ starting_choice = -1;
+ else {
+ starting_choice = args_strtonum(args, 'S', 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
@@ -341,8 +356,8 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
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, target,
+ NULL, NULL) != 0)
return (CMD_RETURN_NORMAL);
return (CMD_RETURN_WAIT);
}
diff --git a/menu.c b/menu.c
index 4aad1d8c..0ff180aa 100644
--- a/menu.c
+++ b/menu.c
@@ -427,12 +427,12 @@ chosen:
}
struct menu_data *
-menu_prepare(struct menu *menu, int flags, struct cmdq_item *item, u_int px,
- u_int py, struct client *c, struct cmd_find_state *fs, menu_choice_cb cb,
- void *data)
+menu_prepare(struct menu *menu, int flags, int starting_choice,
+ struct cmdq_item *item, u_int px, u_int py, struct client *c,
+ struct cmd_find_state *fs, menu_choice_cb cb, void *data)
{
struct menu_data *md;
- u_int i;
+ int choice;
const char *name;
if (c->tty.sx < menu->width + 4 || c->tty.sy < menu->count + 2)
@@ -457,18 +457,38 @@ menu_prepare(struct menu *menu, int flags, struct cmdq_item *item, u_int px,
md->py = py;
md->menu = menu;
+ md->choice = -1;
+
if (md->flags & MENU_NOMOUSE) {
- for (i = 0; i < menu->count; i++) {
- name = menu->items[i].name;
- if (name != NULL && *name != '-')
- break;
+ if (starting_choice >= (int)menu->count) {
+ starting_choice = menu->count - 1;
+ choice = starting_choice + 1;
+ for (;;) {
+ name = menu->items[choice - 1].name;
+ if (name != NULL && *name != '-') {
+ md->choice = choice - 1;
+ break;
+ }
+ if (--choice == 0)
+ choice = menu->count;
+ if (choice == starting_choice + 1)
+ break;
+ }
+ } else if (starting_choice >= 0) {
+ choice = starting_choice;
+ for (;;) {
+ name = menu->items[choice].name;
+ if (name != NULL && *name != '-') {
+ md->choice = choice;
+ break;
+ }
+ if (++choice == (int)menu->count)
+ choice = 0;
+ if (choice == starting_choice)
+ break;
+ }
}
- if (i != menu->count)
- md->choice = i;
- else
- md->choice = -1;
- } else
- md->choice = -1;
+ }
md->cb = cb;
md->data = data;
@@ -476,13 +496,14 @@ menu_prepare(struct menu *menu, int flags, struct cmdq_item *item, u_int px,
}
int
-menu_display(struct menu *menu, int flags, struct cmdq_item *item, u_int px,
- u_int py, struct client *c, struct cmd_find_state *fs, menu_choice_cb cb,
- void *data)
+menu_display(struct menu *menu, int flags, int starting_choice,
+ struct cmdq_item *item, u_int px, u_int py, struct client *c,
+ struct cmd_find_state *fs, menu_choice_cb cb, void *data)
{
struct menu_data *md;
- md = menu_prepare(menu, flags, item, px, py, c, fs, cb, data);
+ md = menu_prepare(menu, flags, starting_choice, item, px, py, c, fs, cb,
+ data);
if (md == NULL)
return (-1);
server_client_set_overlay(c, 0, NULL, menu_mode_cb, menu_draw_cb,
diff --git a/mode-tree.c b/mode-tree.c
index c007e27f..9d465e7b 100644
--- a/mode-tree.c
+++ b/mode-tree.c
@@ -962,8 +962,8 @@ mode_tree_display_menu(struct mode_tree_data *mtd, struct client *c, u_int x,
x -= (menu->width + 4) / 2;
else
x = 0;
- if (menu_display(menu, 0, NULL, x, y, c, NULL, mode_tree_menu_callback,
- mtm) != 0)
+ if (menu_display(menu, 0, 0, NULL, x, y, c, NULL,
+ mode_tree_menu_callback, mtm) != 0)
menu_free(menu);
}
diff --git a/popup.c b/popup.c
index 12f31c40..250888a8 100644
--- a/popup.c
+++ b/popup.c
@@ -574,7 +574,7 @@ menu:
x = m->x - (pd->menu->width + 4) / 2;
else
x = 0;
- pd->md = menu_prepare(pd->menu, 0, NULL, x, m->y, c, NULL,
+ pd->md = menu_prepare(pd->menu, 0, 0, NULL, x, m->y, c, NULL,
popup_menu_done, pd);
c->flags |= CLIENT_REDRAWOVERLAY;
diff --git a/status.c b/status.c
index b504bbbe..08952f58 100644
--- a/status.c
+++ b/status.c
@@ -1766,7 +1766,7 @@ status_prompt_complete_list_menu(struct client *c, char **list, u_int size,
else
offset = 0;
- if (menu_display(menu, MENU_NOMOUSE|MENU_TAB, NULL, offset,
+ if (menu_display(menu, MENU_NOMOUSE|MENU_TAB, 0, NULL, offset,
py, c, NULL, status_prompt_menu_callback, spm) != 0) {
menu_free(menu);
free(spm);
@@ -1859,7 +1859,7 @@ status_prompt_complete_window_menu(struct client *c, struct session *s,
else
offset = 0;
- if (menu_display(menu, MENU_NOMOUSE|MENU_TAB, NULL, offset,
+ if (menu_display(menu, MENU_NOMOUSE|MENU_TAB, 0, NULL, offset,
py, c, NULL, status_prompt_menu_callback, spm) != 0) {
menu_free(menu);
free(spm);
diff --git a/tmux.1 b/tmux.1
index 6a0bfe52..c75afd24 100644
--- a/tmux.1
+++ b/tmux.1
@@ -5815,6 +5815,7 @@ until it is dismissed.
.Op Fl O
.Op Fl c Ar target-client
.Op Fl t Ar target-pane
+.Op Fl S Ar starting-choice
.Op Fl T Ar title
.Op Fl x Ar position
.Op Fl y Ar position
@@ -5844,6 +5845,9 @@ command should be omitted.
.Fl T
is a format for the menu title (see
.Sx FORMATS ) .
+.Fl S
+sets the menu item selected by default, if the menu is not bound to a mouse key
+binding.
.Pp
.Fl x
and
diff --git a/tmux.h b/tmux.h
index 718a067b..3b1a4fc9 100644
--- a/tmux.h
+++ b/tmux.h
@@ -3292,11 +3292,11 @@ void menu_add_item(struct menu *, const struct menu_item *,
struct cmdq_item *, struct client *,
struct cmd_find_state *);
void menu_free(struct menu *);
-struct menu_data *menu_prepare(struct menu *, int, struct cmdq_item *, u_int,
- u_int, struct client *, struct cmd_find_state *,
+struct menu_data *menu_prepare(struct menu *, int, int, struct cmdq_item *,
+ u_int, u_int, struct client *, struct cmd_find_state *,
menu_choice_cb, void *);
-int menu_display(struct menu *, int, struct cmdq_item *, u_int,
- u_int, struct client *, struct cmd_find_state *,
+int menu_display(struct menu *, int, int, struct cmdq_item *,
+ u_int, u_int, struct client *, struct cmd_find_state *,
menu_choice_cb, void *);
struct screen *menu_mode_cb(struct client *, void *, u_int *, u_int *);
void menu_check_cb(struct client *, void *, u_int, u_int, u_int,