Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Length of %? in prompt



On Thu, 28 Feb 2002, Ian Lynagh wrote:

> What I'm doing is something like this:
>
> /--stuff--more stuff--some more stuff--------------------
>
> and I am then truncating this to the screen width with \ (using / and \
> for top-left and top-right corner characters respectively). The border
> is in graphics mode and bold cyan while the various stuffs are in
> various colours and normal text mode, so if it gets truncated in the
> middle of them I am getting a text letter k in whatever colour happens
> to be there. Therefore I want to set the colour and have a ^N in the
> truncating string.

OK, the point is that you don't want the upper right corner to be a
different color or character just because the string was truncated.  Thus
what you want to do here is sacrifice one additional character so that the
"truncating string" (let's call it the "ellipsis" since it plays the role
of the "..." in a truncated sentence) and the truncated string (let's call
that the "sentence" for the same reason) both end with the same character,
and that character is not a terminal control sequence.  Then, _after_ the
%<< that closes the sentence, you emit the correct color and the upper
right corner.  Don't worry about changing the color only if it's wrong,
just always force it to be right.

So something like (still using / and \ rather than graphics chars):

UL="$fg_bold[cyan]/"	# upper left
UR="$fg_bold[cyan]\\"	# upper right
PS1='$UL%$((COLUMNS-4))>->-stuff--more stuff--some more stuff---%<<$UR
\$ $reset_color'

(There's an embedded newline in that PS1 example.)

For a much more complicated example of this same thing, see

	Functions/Prompts/prompt_adam2_setup

in the 4.0.4 distribution.



Messages sorted by: Reverse Date, Date, Thread, Author