mirror of
https://github.com/tmux/tmux.git
synced 2025-01-05 23:38:48 +00:00
Support negative trim values (#{=-10:pane_title}) to trim from the end,
suggested by Kevin Brubeck Unhammer.
This commit is contained in:
parent
225a384dbb
commit
8028560f82
12
format.c
12
format.c
@ -684,7 +684,7 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
||||
char *copy, *copy0, *endptr, *ptr, *found, *new, *value;
|
||||
char *from = NULL, *to = NULL;
|
||||
size_t valuelen, newlen, fromlen, tolen, used;
|
||||
u_long limit = 0;
|
||||
long limit = 0;
|
||||
int modifiers = 0, brackets;
|
||||
|
||||
/* Make a copy of the key. */
|
||||
@ -696,8 +696,8 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
||||
switch (copy[0]) {
|
||||
case '=':
|
||||
errno = 0;
|
||||
limit = strtoul(copy + 1, &endptr, 10);
|
||||
if (errno == ERANGE && limit == ULONG_MAX)
|
||||
limit = strtol(copy + 1, &endptr, 10);
|
||||
if (errno == ERANGE && (limit == LONG_MIN || limit == LONG_MAX))
|
||||
break;
|
||||
if (*endptr != ':')
|
||||
break;
|
||||
@ -813,10 +813,14 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
||||
}
|
||||
|
||||
/* Truncate the value if needed. */
|
||||
if (limit != 0) {
|
||||
if (limit > 0) {
|
||||
new = utf8_trimcstr(value, limit);
|
||||
free(value);
|
||||
value = new;
|
||||
} else if (limit < 0) {
|
||||
new = utf8_rtrimcstr(value, -limit);
|
||||
free(value);
|
||||
value = new;
|
||||
}
|
||||
|
||||
/* Expand the buffer and copy in the value. */
|
||||
|
10
tmux.1
10
tmux.1
@ -3377,9 +3377,13 @@ if not.
|
||||
A limit may be placed on the length of the resultant string by prefixing it
|
||||
by an
|
||||
.Ql = ,
|
||||
a number and a colon, so
|
||||
.Ql #{=10:pane_title}
|
||||
will include at most the first 10 characters of the pane title.
|
||||
a number and a colon.
|
||||
Positive numbers count from the start of the string and negative from the end,
|
||||
so
|
||||
.Ql #{=5:pane_title}
|
||||
will include at most the first 5 characters of the pane title, or
|
||||
.Ql #{=-5:pane_title}
|
||||
the last 5 characters.
|
||||
Prefixing a time variable with
|
||||
.Ql t:
|
||||
will convert it to a string, so if
|
||||
|
Loading…
Reference in New Issue
Block a user