diff options
author | nicm <nicm> | 2022-05-31 10:22:42 +0000 |
---|---|---|
committer | nicm <nicm> | 2022-05-31 10:22:42 +0000 |
commit | 86a184b288bca66ec62706f413b7c151cb0850a4 (patch) | |
tree | 698d09aa5e14b88a1ced4ec7b3e1ca2eaa2cdc42 | |
parent | 58c8ea120943232887b2d4be53b77009c504af06 (diff) | |
download | rtmux-86a184b288bca66ec62706f413b7c151cb0850a4.tar.gz rtmux-86a184b288bca66ec62706f413b7c151cb0850a4.tar.bz2 rtmux-86a184b288bca66ec62706f413b7c151cb0850a4.zip |
Trim menu item text correctly, GitHub issue 3197.
-rw-r--r-- | menu.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -56,7 +56,7 @@ menu_add_item(struct menu *menu, const struct menu_item *item, { struct menu_item *new_item; const char *key = NULL, *cmd, *suffix = ""; - char *s, *name; + char *s, *trimmed, *name; u_int width, max_width; int line; size_t keylen, slen; @@ -103,11 +103,13 @@ menu_add_item(struct menu *menu, const struct menu_item *item, max_width--; 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); + trimmed = format_trim_right(s, max_width); + if (key != NULL) { + xasprintf(&name, "%s%s#[default] #[align=right](%s)", + trimmed, suffix, key); + } else + xasprintf(&name, "%s%s", trimmed, suffix); + free(trimmed); new_item->name = name; free(s); |