summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/menu.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2019-05-26 17:34:46 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2019-05-26 17:34:46 +0000
commitd42f75e5c0133d899df058f961447782d34b158a (patch)
tree3b2c39dad3e63840d0b3198f9194293f2bce8803 /usr.bin/tmux/menu.c
parent48405956365d8c4a9a95d0823ee24aaa49eec67f (diff)
Add formats for word and line under the mouse and use them to add some
items to the pane menu.
Diffstat (limited to 'usr.bin/tmux/menu.c')
-rw-r--r--usr.bin/tmux/menu.c50
1 files changed, 31 insertions, 19 deletions
diff --git a/usr.bin/tmux/menu.c b/usr.bin/tmux/menu.c
index 96bde640535..4e7c1b5a4df 100644
--- a/usr.bin/tmux/menu.c
+++ b/usr.bin/tmux/menu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: menu.c,v 1.5 2019/05/23 11:13:30 nicm Exp $ */
+/* $OpenBSD: menu.c,v 1.6 2019/05/26 17:34:45 nicm Exp $ */
/*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -41,8 +41,8 @@ struct menu_data {
};
static void
-menu_add_item(struct menu *menu, struct menu_item *item, struct client *c,
- struct cmd_find_state *fs)
+menu_add_item(struct menu *menu, struct menu_item *item,
+ struct cmdq_item *qitem, struct client *c, struct cmd_find_state *fs)
{
struct menu_item *new_item;
const char *key;
@@ -57,24 +57,31 @@ menu_add_item(struct menu *menu, struct menu_item *item, struct client *c,
if (item == NULL || *item->name == '\0') /* horizontal line */
return;
if (fs != NULL) {
- name = format_single(NULL, item->name, c, fs->s, fs->wl,
+ name = format_single(qitem, item->name, c, fs->s, fs->wl,
fs->wp);
} else
- name = xstrdup(item->name);
+ name = format_single(qitem, item->name, c, NULL, NULL, NULL);
if (*name == '\0') { /* no item if empty after format expanded */
menu->count--;
return;
}
if (item->key != KEYC_UNKNOWN) {
key = key_string_lookup_key(item->key);
- xasprintf(&new_item->name, "%s #[align=right](%s)", name, key);
+ xasprintf(&new_item->name, "%s#[default] #[align=right](%s)",
+ name, key);
} else
xasprintf(&new_item->name, "%s", name);
free(name);
- if (item->command != NULL)
- new_item->command = xstrdup(item->command);
- else
+ if (item->command != NULL) {
+ if (fs != NULL) {
+ new_item->command = format_single(qitem, item->command,
+ c, fs->s, fs->wl, fs->wp);
+ } else {
+ new_item->command = format_single(qitem, item->command,
+ c, NULL, NULL, NULL);
+ }
+ } else
new_item->command = NULL;
new_item->key = item->key;
@@ -84,8 +91,8 @@ menu_add_item(struct menu *menu, struct menu_item *item, struct client *c,
}
static void
-menu_parse_item(struct menu *menu, const char *s, struct client *c,
- struct cmd_find_state *fs)
+menu_parse_item(struct menu *menu, const char *s, struct cmdq_item *qitem,
+ struct client *c, struct cmd_find_state *fs)
{
char *copy, *first;
const char *second, *third;
@@ -100,15 +107,15 @@ menu_parse_item(struct menu *menu, const char *s, struct client *c,
item.name = first;
item.command = (char *)third;
item.key = key_string_lookup_string(second);
- menu_add_item(menu, &item, c, fs);
+ menu_add_item(menu, &item, qitem, c, fs);
}
}
free(copy);
}
struct menu *
-menu_create(const char *s, struct client *c, struct cmd_find_state *fs,
- const char *title)
+menu_create(const char *s, struct cmdq_item *qitem, struct client *c,
+ struct cmd_find_state *fs, const char *title)
{
struct menu *menu;
char *copy, *string, *next;
@@ -124,10 +131,11 @@ menu_create(const char *s, struct client *c, struct cmd_find_state *fs,
next = (char *)format_skip(string, "|");
if (next != NULL)
*next++ = '\0';
- if (*string == '\0')
- menu_add_item(menu, NULL, c, fs);
- else
- menu_parse_item(menu, string, c, fs);
+ if (*string == '\0') {
+ if (menu->count != 0)
+ menu_add_item(menu, NULL, qitem, c, fs);
+ } else
+ menu_parse_item(menu, string, qitem, c, fs);
string = next;
} while (next != NULL);
free(copy);
@@ -283,7 +291,11 @@ chosen:
cmdq_append(c, new_item);
break;
case CMD_PARSE_SUCCESS:
- new_item = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
+ if (md->item != NULL)
+ m = &md->item->shared->mouse;
+ else
+ m = NULL;
+ new_item = cmdq_get_command(pr->cmdlist, &md->fs, m, 0);
cmd_list_free(pr->cmdlist);
cmdq_append(c, new_item);
break;