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

Prompt code patch



-----BEGIN PGP SIGNED MESSAGE-----

Below is a large patch to the prompt expansion code.  It solves the
following problems:

o If the prompt changes while ZLE is active, e.g. if a completion on ~
  involving a list being output causes a path in the prompt to be
  abbreviated, then the prompt does not actually change on the screen
  until a redisplay is done, but its new length is used immediately.
  This is solved by not recalculating the prompt in such
  circumstances.

o The prompt is truncated to 256 characters.  After the patch, memory
  for the prompt is dynamically allocated, also removing the necessity
  for the kludgy three rotated fixed-length buffers.

o Prompts an exact multiple of the screen width, or one less, in length
  get an extra space added, which ZLE displays, but ZLE thinks the
  prompt doesn't go that far onto the screen.  The code to do this was
  also invoking undefined behaviour a little.

o In some cases of the prompt format string ending unexpectedly, such
  as if it consists only of a single % character, the prompt expansion
  code walks off the end of the string and return garbage.

o Truncation of %~ doesn't work, big time.

In addition, it documents the %[ (truncation control) sequence.  Could
whoever designed that bit (it's rather good) please check that I got it
right -- I think I got down everything relevant from the source, but
I'm not certain.

(Is anyone still reading this?)  There are a couple of odd bits of code
in there that I'm not sure should be there.  Can someone explain why
these are in there, and whether we need them:

o A ! on its own is replaced by the history number.  Considering that
  %! already does this, is this necessary?  It's the only special
  sequence that doesn't start with a %, so it's an ugly exception.

o Another ugly exception is that a backslash will escape the next
  character.  As the only characters that need escaping are % (which
  can be escaped by doubling to %% anyway) and the aforementioned !
  (which IMHO shouldn't have that special behaviour), isn't it rather
  nasty to have \ special like this?  Or is this for PROMPT_SUBST --
  isn't there another solution for escaping $ characters?

o Prompts of a multiple of the screen width (other than 0), and one
  less, in length get spaces added to take them to one greater than a
  multiple of the screen width.  What's the point?

Finally: should %{/%} pairs nest?  I think they should, and it's pretty
easy to add.

 -zefram

begin 600 prompt-diffs.gz
M'XL(" Z  3   W!R;VUP="UD:69F<P#56_MOVT:V_EG]*\9>)'I1#BE9LF0W
M+?HPBNSF=H,TBP5N$J0T-;*)4"1!4E:=-OW;[W?./#B4*<>[]>UFA42F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