aboutsummaryrefslogtreecommitdiff
path: root/menu.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2021-12-07 09:52:59 +0000
committerThomas Adam <thomas@xteddy.org>2021-12-07 09:52:59 +0000
commit138ffc7cb6225b8a6d54d771b0112635f0dbb42e (patch)
tree289b9f8c4ca207f92b6d81f9511c520969241120 /menu.c
parentef676e1202a4d5c423d5bba2f8ecba1f768d8364 (diff)
parentd721fb2a9fd70c157abb8540d4c50fca654f9f4d (diff)
downloadrtmux-138ffc7cb6225b8a6d54d771b0112635f0dbb42e.tar.gz
rtmux-138ffc7cb6225b8a6d54d771b0112635f0dbb42e.tar.bz2
rtmux-138ffc7cb6225b8a6d54d771b0112635f0dbb42e.zip
Merge branch 'obsd-master' into master
Diffstat (limited to 'menu.c')
-rw-r--r--menu.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/menu.c b/menu.c
index 45645147..aaa1287e 100644
--- a/menu.c
+++ b/menu.c
@@ -89,22 +89,26 @@ menu_add_item(struct menu *menu, const struct menu_item *item,
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.
+ * Add the key if it is shorter than a quarter of the available
+ * 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;
}
+ if (slen > max_width) {
+ max_width--;
+ suffix = ">";
+ }
if (key != NULL)
- xasprintf(&name, "%s#[default] #[align=right](%s)", s, key);
- else {
- if (slen > max_width) {
- max_width--;
- suffix = ">";
- }
+ 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;
free(s);