summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2021-11-11 09:22:34 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2021-11-11 09:22:34 +0000
commitffa5e97918b7e253fcaa562b31ba76926612e5a0 (patch)
tree65f0b5a97aed7aeca1bc8b4c6f60c501a4b283b3
parent646470bf20c7fd116e2fa980306d6c9198d67b9e (diff)
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.
-rw-r--r--usr.bin/tmux/menu.c26
-rw-r--r--usr.bin/tmux/tmux.17
2 files changed, 19 insertions, 14 deletions
diff --git a/usr.bin/tmux/menu.c b/usr.bin/tmux/menu.c
index 2ed80a5a21b..bb0d6c574a5 100644
--- a/usr.bin/tmux/menu.c
+++ b/usr.bin/tmux/menu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: menu.c,v 1.40 2021/10/22 17:12:50 nicm Exp $ */
+/* $OpenBSD: menu.c,v 1.41 2021/11/11 09:22:33 nicm Exp $ */
/*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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);
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 2bfbcd3e1d8..a965b7f9ffe 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.870 2021/11/04 13:15:13 kn Exp $
+.\" $OpenBSD: tmux.1,v 1.871 2021/11/11 09:22:33 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: November 4 2021 $
+.Dd $Mdocdate: November 11 2021 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -4427,7 +4427,8 @@ uses when the colour with that index is requested.
The index may be from zero to 255.
.Pp
.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 blinking-block ,
.Ic block ,