diff options
author | Thomas Adam <thomas@xteddy.org> | 2021-10-22 20:01:11 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2021-10-22 20:01:11 +0100 |
commit | 5071b82c77639344db8f91a9ad5b040be796d953 (patch) | |
tree | 3c3a69b5d9a4202038747118a3241b03a282778b /menu.c | |
parent | be2413292f6e94aca0a5c707254db62a2b186f84 (diff) | |
parent | 8235957eaae0aacb1ad0c9b145a1f9d3abc93dfd (diff) | |
download | rtmux-5071b82c77639344db8f91a9ad5b040be796d953.tar.gz rtmux-5071b82c77639344db8f91a9ad5b040be796d953.tar.bz2 rtmux-5071b82c77639344db8f91a9ad5b040be796d953.zip |
Merge branch 'obsd-master' into master
Diffstat (limited to 'menu.c')
-rw-r--r-- | menu.c | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -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 menu_item *new_item; - const char *key, *cmd; + const char *key = NULL, *cmd, *suffix = ""; char *s, *name; - u_int width; + u_int width, max_width; int line; + size_t keylen, slen; line = (item == NULL || item->name == NULL || *item->name == '\0'); if (line && menu->count == 0) @@ -80,11 +81,30 @@ menu_add_item(struct menu *menu, const struct menu_item *item, menu->count--; return; } + max_width = c->tty.sx - 4; + + slen = strlen(s); if (*s != '-' && item->key != KEYC_UNKNOWN && item->key != KEYC_NONE) { 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); - } else - xasprintf(&name, "%s", s); + else { + if (slen > max_width) { + max_width--; + suffix = ">"; + } + xasprintf(&name, "%.*s%s", (int)max_width, s, suffix); + } new_item->name = name; free(s); |