mirror of
https://github.com/tmux/tmux.git
synced 2025-01-08 08:58:47 +00:00
Allow menu items to be disabled by putting a - at the start of their
name, rather than just including #[dim] which still allowed them to be chosen.
This commit is contained in:
parent
799a154b91
commit
12255411f2
@ -299,7 +299,7 @@ key_bindings_init(void)
|
|||||||
"bind -n MouseDown3Status display-menu -t= -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\""
|
"bind -n MouseDown3Status display-menu -t= -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\""
|
||||||
" 'Swap Left' 'l' {swap-window -t:-1}"
|
" 'Swap Left' 'l' {swap-window -t:-1}"
|
||||||
" 'Swap Right' 'r' {swap-window -t:+1}"
|
" 'Swap Right' 'r' {swap-window -t:+1}"
|
||||||
" '#{?pane_marked_set,,#[dim]}Swap Marked' 's' {swap-window}"
|
" '#{?pane_marked_set,,-}Swap Marked' 's' {swap-window}"
|
||||||
" ''"
|
" ''"
|
||||||
" 'Kill' 'X' {kill-window}"
|
" 'Kill' 'X' {kill-window}"
|
||||||
" 'Respawn' 'R' {respawn-window -k}"
|
" 'Respawn' 'R' {respawn-window -k}"
|
||||||
@ -319,7 +319,7 @@ key_bindings_init(void)
|
|||||||
" ''"
|
" ''"
|
||||||
" 'Swap Up' 'u' {swap-pane -U}"
|
" 'Swap Up' 'u' {swap-pane -U}"
|
||||||
" 'Swap Down' 'd' {swap-pane -D}"
|
" 'Swap Down' 'd' {swap-pane -D}"
|
||||||
" '#{?pane_marked_set,,#[dim]}Swap Marked' 's' {swap-pane}"
|
" '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane}"
|
||||||
" ''"
|
" ''"
|
||||||
" 'Kill' 'X' {kill-pane}"
|
" 'Kill' 'X' {kill-pane}"
|
||||||
" 'Respawn' 'R' {respawn-pane -k}"
|
" 'Respawn' 'R' {respawn-pane -k}"
|
||||||
|
18
menu.c
18
menu.c
@ -80,7 +80,7 @@ menu_add_item(struct menu *menu, const struct menu_item *item,
|
|||||||
menu->count--;
|
menu->count--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (item->key != KEYC_UNKNOWN && item->key != KEYC_NONE) {
|
if (*s != '-' && item->key != KEYC_UNKNOWN && item->key != KEYC_NONE) {
|
||||||
key = key_string_lookup_key(item->key);
|
key = key_string_lookup_key(item->key);
|
||||||
xasprintf(&name, "%s#[default] #[align=right](%s)", s, key);
|
xasprintf(&name, "%s#[default] #[align=right](%s)", s, key);
|
||||||
} else
|
} else
|
||||||
@ -182,6 +182,7 @@ menu_key_cb(struct client *c, struct key_event *event)
|
|||||||
const struct menu_item *item;
|
const struct menu_item *item;
|
||||||
struct cmdq_item *new_item;
|
struct cmdq_item *new_item;
|
||||||
struct cmd_parse_result *pr;
|
struct cmd_parse_result *pr;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
if (KEYC_IS_MOUSE(event->key)) {
|
if (KEYC_IS_MOUSE(event->key)) {
|
||||||
if (md->flags & MENU_NOMOUSE)
|
if (md->flags & MENU_NOMOUSE)
|
||||||
@ -207,21 +208,27 @@ menu_key_cb(struct client *c, struct key_event *event)
|
|||||||
}
|
}
|
||||||
switch (event->key) {
|
switch (event->key) {
|
||||||
case KEYC_UP:
|
case KEYC_UP:
|
||||||
|
if (old == -1)
|
||||||
|
old = 0;
|
||||||
do {
|
do {
|
||||||
if (md->choice == -1 || md->choice == 0)
|
if (md->choice == -1 || md->choice == 0)
|
||||||
md->choice = count - 1;
|
md->choice = count - 1;
|
||||||
else
|
else
|
||||||
md->choice--;
|
md->choice--;
|
||||||
} while (menu->items[md->choice].name == NULL);
|
name = menu->items[md->choice].name;
|
||||||
|
} while ((name == NULL || *name == '-') && md->choice != old);
|
||||||
c->flags |= CLIENT_REDRAWOVERLAY;
|
c->flags |= CLIENT_REDRAWOVERLAY;
|
||||||
return (0);
|
return (0);
|
||||||
case KEYC_DOWN:
|
case KEYC_DOWN:
|
||||||
|
if (old == -1)
|
||||||
|
old = 0;
|
||||||
do {
|
do {
|
||||||
if (md->choice == -1 || md->choice == count - 1)
|
if (md->choice == -1 || md->choice == count - 1)
|
||||||
md->choice = 0;
|
md->choice = 0;
|
||||||
else
|
else
|
||||||
md->choice++;
|
md->choice++;
|
||||||
} while (menu->items[md->choice].name == NULL);
|
name = menu->items[md->choice].name;
|
||||||
|
} while ((name == NULL || *name == '-') && md->choice != old);
|
||||||
c->flags |= CLIENT_REDRAWOVERLAY;
|
c->flags |= CLIENT_REDRAWOVERLAY;
|
||||||
return (0);
|
return (0);
|
||||||
case '\r':
|
case '\r':
|
||||||
@ -233,6 +240,9 @@ menu_key_cb(struct client *c, struct key_event *event)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
for (i = 0; i < (u_int)count; i++) {
|
for (i = 0; i < (u_int)count; i++) {
|
||||||
|
name = menu->items[i].name;
|
||||||
|
if (name == NULL || *name == '-')
|
||||||
|
continue;
|
||||||
if (event->key == menu->items[i].key) {
|
if (event->key == menu->items[i].key) {
|
||||||
md->choice = i;
|
md->choice = i;
|
||||||
goto chosen;
|
goto chosen;
|
||||||
@ -244,7 +254,7 @@ chosen:
|
|||||||
if (md->choice == -1)
|
if (md->choice == -1)
|
||||||
return (1);
|
return (1);
|
||||||
item = &menu->items[md->choice];
|
item = &menu->items[md->choice];
|
||||||
if (item->name == NULL)
|
if (item->name == NULL || *item->name == '-')
|
||||||
return (1);
|
return (1);
|
||||||
if (md->cb != NULL) {
|
if (md->cb != NULL) {
|
||||||
md->cb(md->menu, md->choice, item->key, md->data);
|
md->cb(md->menu, md->choice, item->key, md->data);
|
||||||
|
@ -410,6 +410,7 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice)
|
|||||||
struct screen *s = ctx->s;
|
struct screen *s = ctx->s;
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
u_int cx, cy, i, j;
|
u_int cx, cy, i, j;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
cx = s->cx;
|
cx = s->cx;
|
||||||
cy = s->cy;
|
cy = s->cy;
|
||||||
@ -421,18 +422,24 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice)
|
|||||||
format_draw(ctx, &gc, menu->width, menu->title, NULL);
|
format_draw(ctx, &gc, menu->width, menu->title, NULL);
|
||||||
|
|
||||||
for (i = 0; i < menu->count; i++) {
|
for (i = 0; i < menu->count; i++) {
|
||||||
if (menu->items[i].name == NULL) {
|
name = menu->items[i].name;
|
||||||
|
if (name == NULL) {
|
||||||
screen_write_cursormove(ctx, cx, cy + 1 + i, 0);
|
screen_write_cursormove(ctx, cx, cy + 1 + i, 0);
|
||||||
screen_write_hline(ctx, menu->width + 4, 1, 1);
|
screen_write_hline(ctx, menu->width + 4, 1, 1);
|
||||||
} else {
|
} else {
|
||||||
if (choice >= 0 && i == (u_int)choice)
|
if (choice >= 0 && i == (u_int)choice && *name != '-')
|
||||||
gc.attr |= GRID_ATTR_REVERSE;
|
gc.attr |= GRID_ATTR_REVERSE;
|
||||||
screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
|
screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
|
||||||
for (j = 0; j < menu->width; j++)
|
for (j = 0; j < menu->width; j++)
|
||||||
screen_write_putc(ctx, &gc, ' ');
|
screen_write_putc(ctx, &gc, ' ');
|
||||||
screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
|
screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
|
||||||
format_draw(ctx, &gc, menu->width, menu->items[i].name,
|
if (*name == '-') {
|
||||||
NULL);
|
name++;
|
||||||
|
gc.attr |= GRID_ATTR_DIM;
|
||||||
|
format_draw(ctx, &gc, menu->width, name, NULL);
|
||||||
|
gc.attr &= ~GRID_ATTR_DIM;
|
||||||
|
} else
|
||||||
|
format_draw(ctx, &gc, menu->width, name, NULL);
|
||||||
if (choice >= 0 && i == (u_int)choice)
|
if (choice >= 0 && i == (u_int)choice)
|
||||||
gc.attr &= ~GRID_ATTR_REVERSE;
|
gc.attr &= ~GRID_ATTR_REVERSE;
|
||||||
}
|
}
|
||||||
|
2
tmux.1
2
tmux.1
@ -4674,6 +4674,8 @@ The name and command are formats, see the
|
|||||||
and
|
and
|
||||||
.Sx STYLES
|
.Sx STYLES
|
||||||
sections.
|
sections.
|
||||||
|
If the name begins with a hyphen (-), then the item is disabled (shown dim) and
|
||||||
|
may not be chosen.
|
||||||
The name may be empty for a separator line, in which case both the key and
|
The name may be empty for a separator line, in which case both the key and
|
||||||
command should be omitted.
|
command should be omitted.
|
||||||
.Pp
|
.Pp
|
||||||
|
Loading…
Reference in New Issue
Block a user