If trimming menu item text, show key if it would take up less than a

quarter of the space; from Alexis Hildebrandt.

Also new sentence, new line in tmux.1, from jmc.
This commit is contained in:
nicm
2021-11-11 09:22:33 +00:00
parent 8f1cc0e9fa
commit 630c592ef8
2 changed files with 17 additions and 12 deletions

26
menu.c
View File

@ -89,22 +89,26 @@ menu_add_item(struct menu *menu, const struct menu_item *item,
keylen = strlen(key) + 3; /* 3 = space and two brackets */ keylen = strlen(key) + 3; /* 3 = space and two brackets */
/* /*
* Only add the key if there is space for the entire item text * Add the key if it is shorter than a quarter of the available
* and the key. * space or there is space for the entire item text and the
* key.
*/ */
if (keylen >= max_width || slen >= max_width - keylen) if (keylen <= max_width / 4)
max_width -= keylen;
else if (keylen >= max_width || slen >= max_width - keylen)
key = NULL; key = NULL;
} }
if (key != NULL) if (slen > max_width) {
xasprintf(&name, "%s#[default] #[align=right](%s)", s, key); max_width--;
else { suffix = ">";
if (slen > max_width) {
max_width--;
suffix = ">";
}
xasprintf(&name, "%.*s%s", (int)max_width, s, suffix);
} }
if (key != NULL)
xasprintf(&name, "%.*s%s#[default] #[align=right](%s)",
(int)max_width, s, suffix, key);
else
xasprintf(&name, "%.*s%s", (int)max_width, s, suffix);
new_item->name = name; new_item->name = name;
free(s); free(s);

3
tmux.1
View File

@ -4427,7 +4427,8 @@ uses when the colour with that index is requested.
The index may be from zero to 255. The index may be from zero to 255.
.Pp .Pp
.It Ic cursor-style Ar style .It Ic cursor-style Ar style
Set the style of the cursor. Available styles are: Set the style of the cursor.
Available styles are:
.Ic default , .Ic default ,
.Ic blinking-block , .Ic blinking-block ,
.Ic block , .Ic block ,