mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 01:48:47 +00:00
Remove key and trim text if menu cannot fit in available space, based on
a change from Alexis Hildebrandt.
This commit is contained in:
parent
289ac55ebd
commit
8235957eaa
28
menu.c
28
menu.c
@ -55,10 +55,11 @@ menu_add_item(struct menu *menu, const struct menu_item *item,
|
|||||||
struct cmdq_item *qitem, struct client *c, struct cmd_find_state *fs)
|
struct cmdq_item *qitem, struct client *c, struct cmd_find_state *fs)
|
||||||
{
|
{
|
||||||
struct menu_item *new_item;
|
struct menu_item *new_item;
|
||||||
const char *key, *cmd;
|
const char *key = NULL, *cmd, *suffix = "";
|
||||||
char *s, *name;
|
char *s, *name;
|
||||||
u_int width;
|
u_int width, max_width;
|
||||||
int line;
|
int line;
|
||||||
|
size_t keylen, slen;
|
||||||
|
|
||||||
line = (item == NULL || item->name == NULL || *item->name == '\0');
|
line = (item == NULL || item->name == NULL || *item->name == '\0');
|
||||||
if (line && menu->count == 0)
|
if (line && menu->count == 0)
|
||||||
@ -80,11 +81,30 @@ menu_add_item(struct menu *menu, const struct menu_item *item,
|
|||||||
menu->count--;
|
menu->count--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
max_width = c->tty.sx - 4;
|
||||||
|
|
||||||
|
slen = strlen(s);
|
||||||
if (*s != '-' && 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, 0);
|
key = key_string_lookup_key(item->key, 0);
|
||||||
|
keylen = strlen(key) + 3; /* 3 = space and two brackets */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Only add the key if there is space for the entire item text
|
||||||
|
* and the key.
|
||||||
|
*/
|
||||||
|
if (keylen >= max_width || slen >= max_width - keylen)
|
||||||
|
key = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key != NULL)
|
||||||
xasprintf(&name, "%s#[default] #[align=right](%s)", s, key);
|
xasprintf(&name, "%s#[default] #[align=right](%s)", s, key);
|
||||||
} else
|
else {
|
||||||
xasprintf(&name, "%s", s);
|
if (slen > max_width) {
|
||||||
|
max_width--;
|
||||||
|
suffix = ">";
|
||||||
|
}
|
||||||
|
xasprintf(&name, "%.*s%s", (int)max_width, s, suffix);
|
||||||
|
}
|
||||||
new_item->name = name;
|
new_item->name = name;
|
||||||
free(s);
|
free(s);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user