mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-27 16:50:58 +01:00
32971: negative argument with %(l..) and with %<< or %>> calculates space available before right margin
This commit is contained in:
parent
c810a072e2
commit
6fc3b67b80
3 changed files with 43 additions and 9 deletions
|
|
@ -1,3 +1,10 @@
|
||||||
|
2014-08-07 Barton E. Schaefer <schaefer@zsh.org>
|
||||||
|
|
||||||
|
* 32971 (plus doc tweak): Doc/Zsh/prompt.yo, Src/prompt.c:
|
||||||
|
negative argument with %(l..) conditional and with %<< or %>>
|
||||||
|
truncation calculates space available before right margin
|
||||||
|
(positive argument still counts space used since left margin).
|
||||||
|
|
||||||
2014-08-04 Barton E. Schaefer <schaefer@brasslantern.com>
|
2014-08-04 Barton E. Schaefer <schaefer@brasslantern.com>
|
||||||
|
|
||||||
* Miles Ohlrich: 32958: Src/Zle/compctl.c: bitwise logic fix
|
* Miles Ohlrich: 32958: Src/Zle/compctl.c: bitwise logic fix
|
||||||
|
|
|
||||||
|
|
@ -302,7 +302,8 @@ sitem(tt(g))(True if the effective gid of the current process is var(n).)
|
||||||
sitem(tt(j))(True if the number of jobs is at least var(n).)
|
sitem(tt(j))(True if the number of jobs is at least var(n).)
|
||||||
sitem(tt(L))(True if the tt(SHLVL) parameter is at least var(n).)
|
sitem(tt(L))(True if the tt(SHLVL) parameter is at least var(n).)
|
||||||
sitem(tt(l))(True if at least var(n) characters have already been
|
sitem(tt(l))(True if at least var(n) characters have already been
|
||||||
printed on the current line.)
|
printed on the current line. When var(n) is negative, true if at least
|
||||||
|
tt(abs)tt(LPAR())var(n)tt(RPAR()) characters remain before the right margin.)
|
||||||
sitem(tt(S))(True if the tt(SECONDS) parameter is at least var(n).)
|
sitem(tt(S))(True if the tt(SECONDS) parameter is at least var(n).)
|
||||||
sitem(tt(T))(True if the time in hours is equal to var(n).)
|
sitem(tt(T))(True if the time in hours is equal to var(n).)
|
||||||
sitem(tt(t))(True if the time in minutes is equal to var(n).)
|
sitem(tt(t))(True if the time in minutes is equal to var(n).)
|
||||||
|
|
@ -318,13 +319,21 @@ item(tt(%[)var(xstring)tt(]))(
|
||||||
Specifies truncation behaviour for the remainder of the prompt string.
|
Specifies truncation behaviour for the remainder of the prompt string.
|
||||||
The third, deprecated, form is equivalent to `tt(%)var(xstringx)',
|
The third, deprecated, form is equivalent to `tt(%)var(xstringx)',
|
||||||
i.e. var(x) may be `tt(<)' or `tt(>)'.
|
i.e. var(x) may be `tt(<)' or `tt(>)'.
|
||||||
The numeric argument, which in the third form may appear immediately
|
|
||||||
after the `tt([)', specifies the maximum permitted length of
|
|
||||||
the various strings that can be displayed in the prompt.
|
|
||||||
The var(string) will be displayed in
|
The var(string) will be displayed in
|
||||||
place of the truncated portion of any string; note this does not
|
place of the truncated portion of any string; note this does not
|
||||||
undergo prompt expansion.
|
undergo prompt expansion.
|
||||||
|
|
||||||
|
The numeric argument, which in the third form may appear immediately
|
||||||
|
after the `tt([)', specifies the maximum permitted length of
|
||||||
|
the various strings that can be displayed in the prompt.
|
||||||
|
In the first two forms, this numeric argument may be negative, in which
|
||||||
|
case the truncation length is determined by subtracting the absolute
|
||||||
|
value of the numeric argument from the number of character positions
|
||||||
|
remaining on the current prompt line. If this results in a zero or
|
||||||
|
negative length, a length of 1 is used. In other words, a negative
|
||||||
|
argument arranges that after truncation at least var(n) characters
|
||||||
|
remain before the right margin.
|
||||||
|
|
||||||
The forms with `tt(<)' truncate at the left of the string,
|
The forms with `tt(<)' truncate at the left of the string,
|
||||||
and the forms with `tt(>)' truncate at the right of the string.
|
and the forms with `tt(>)' truncate at the right of the string.
|
||||||
For example, if the current directory is `tt(/home/pike)',
|
For example, if the current directory is `tt(/home/pike)',
|
||||||
|
|
@ -344,11 +353,19 @@ string, or to the end of the next enclosing group of the `tt(%LPAR())'
|
||||||
construct, or to the next truncation encountered at the same grouping
|
construct, or to the next truncation encountered at the same grouping
|
||||||
level (i.e. truncations inside a `tt(%LPAR())' are separate), which
|
level (i.e. truncations inside a `tt(%LPAR())' are separate), which
|
||||||
ever comes first. In particular, a truncation with argument zero
|
ever comes first. In particular, a truncation with argument zero
|
||||||
(e.g. `tt(%<<)') marks the end of the range of the string to be
|
(e.g., `tt(%<<)') marks the end of the range of the string to be
|
||||||
truncated while turning off truncation from there on. For example, the
|
truncated while turning off truncation from there on. For example, the
|
||||||
prompt '%10<...<%~%<<%# ' will print a truncated representation of the
|
prompt '%10<...<%~%<<%# ' will print a truncated representation of the
|
||||||
current directory, followed by a `tt(%)' or `tt(#)', followed by a
|
current directory, followed by a `tt(%)' or `tt(#)', followed by a
|
||||||
space. Without the `tt(%<<)', those two characters would be included
|
space. Without the `tt(%<<)', those two characters would be included
|
||||||
in the string to be truncated.
|
in the string to be truncated. Note that `tt(%-0<<)' is a distinct
|
||||||
|
|
||||||
|
Truncation applies only within each individual line of the prompt, as
|
||||||
|
delimited by embedded newlines (if any). If the total length of any line
|
||||||
|
of the prompt after truncation is greater than the terminal width, or if
|
||||||
|
the part to be truncated contains embedded newlines, truncation behavior
|
||||||
|
is undefined and may change in a future version of the shell. Use
|
||||||
|
`tt(%-var(n)LPAR()l.var(true-text).var(false-text)RPAR())' to remove parts
|
||||||
|
of the prompt when the available space is less than var(n).
|
||||||
)
|
)
|
||||||
enditem()
|
enditem()
|
||||||
|
|
|
||||||
16
Src/prompt.c
16
Src/prompt.c
|
|
@ -367,6 +367,8 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
|
||||||
case 'l':
|
case 'l':
|
||||||
*bv->bp = '\0';
|
*bv->bp = '\0';
|
||||||
countprompt(bv->bufline, &t0, 0, 0);
|
countprompt(bv->bufline, &t0, 0, 0);
|
||||||
|
if (minus)
|
||||||
|
t0 = zterm_columns - t0;
|
||||||
if (t0 >= arg)
|
if (t0 >= arg)
|
||||||
test = 1;
|
test = 1;
|
||||||
break;
|
break;
|
||||||
|
|
@ -560,6 +562,14 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
|
||||||
break;
|
break;
|
||||||
case '<':
|
case '<':
|
||||||
case '>':
|
case '>':
|
||||||
|
/* Test (minus) here so -0 means "at the right margin" */
|
||||||
|
if (minus) {
|
||||||
|
*bv->bp = '\0';
|
||||||
|
countprompt(bv->bufline, &t0, 0, 0);
|
||||||
|
arg = zterm_columns - t0 + arg;
|
||||||
|
if (arg <= 0)
|
||||||
|
arg = 1;
|
||||||
|
}
|
||||||
if (!prompttrunc(arg, *bv->fm, doprint, endchar, txtchangep))
|
if (!prompttrunc(arg, *bv->fm, doprint, endchar, txtchangep))
|
||||||
return *bv->fm;
|
return *bv->fm;
|
||||||
break;
|
break;
|
||||||
|
|
@ -1174,7 +1184,7 @@ prompttrunc(int arg, int truncchar, int doprint, int endchar,
|
||||||
addbufspc(1);
|
addbufspc(1);
|
||||||
*bv->bp++ = '<';
|
*bv->bp++ = '<';
|
||||||
}
|
}
|
||||||
ptr = bv->buf + w; /* addbv->bufspc() may have realloc()'d bv->buf */
|
ptr = bv->buf + w; /* addbufspc() may have realloc()'d bv->buf */
|
||||||
/*
|
/*
|
||||||
* Now:
|
* Now:
|
||||||
* bv->buf is the start of the output prompt buffer
|
* bv->buf is the start of the output prompt buffer
|
||||||
|
|
@ -1189,7 +1199,7 @@ prompttrunc(int arg, int truncchar, int doprint, int endchar,
|
||||||
bv->trunccount = bv->dontcount;
|
bv->trunccount = bv->dontcount;
|
||||||
putpromptchar(doprint, endchar, txtchangep);
|
putpromptchar(doprint, endchar, txtchangep);
|
||||||
bv->trunccount = 0;
|
bv->trunccount = 0;
|
||||||
ptr = bv->buf + w; /* putpromptchar() may have realloc()'d */
|
ptr = bv->buf + w; /* putpromptchar() may have realloc()'d */
|
||||||
*bv->bp = '\0';
|
*bv->bp = '\0';
|
||||||
/*
|
/*
|
||||||
* Now:
|
* Now:
|
||||||
|
|
@ -1475,7 +1485,7 @@ prompttrunc(int arg, int truncchar, int doprint, int endchar,
|
||||||
/* Now we have to trick it into matching endchar again */
|
/* Now we have to trick it into matching endchar again */
|
||||||
bv->fm--;
|
bv->fm--;
|
||||||
} else {
|
} else {
|
||||||
if (*bv->fm != ']')
|
if (*bv->fm != endchar)
|
||||||
bv->fm++;
|
bv->fm++;
|
||||||
while(*bv->fm && *bv->fm != truncchar) {
|
while(*bv->fm && *bv->fm != truncchar) {
|
||||||
if (*bv->fm == '\\' && bv->fm[1])
|
if (*bv->fm == '\\' && bv->fm[1])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue