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

Re: since 4.3.4, artifact-appearance at prompt



On Nov 4,  8:00pm, Atom Smasher wrote:
}
} > On Sat, 3 Nov 2007, Russell Hoover wrote:
} > "%" on a blank line where I'm not sure it's doing me any good (when my 
} > prompt is already on the next line).

Note in passing:  You're not supposed to see the % on a blank line.  The
PROMPT_SP trick is supposed to emit just enough spaces so that, *if* the
line is blank, then when the PROMP_CR carriage return is printed, you'll
be returned to the position where the % appears and the normal prompt
will cover it up.

This is why I say you're either in a race condition -- e.g., zsh prints
the spaces but before it can backspace and print the prompt, you hit
enter again and the teminal advances to the next line [*] -- or there's
something unexpected about the right-margin auto-wrap behavior of your
terminal, such that the PROMPT_SP spaces cause a new line where one
should not be.

[*] I can't make this happen no matter how fast I hammer on the enter
key, so I suspect this is related to other problems with slow prompts.

Ok, that got windier than I intended.  Back to the real reply:

On Nov 4,  8:00pm, Atom Smasher wrote:
}
} would it be reasonable to have an SPPROMPT parameter, or something 
} similar, to control what's displayed there?

It wouldn't be unreasonable, but it would require the prompt_sp code to
be able to compute the exact visible width of that substitution -- that
is, users would have to be just as careful with %{ and %} as they are
in the prompt itself, maybe more so.

If you want to control what appears there, you can unsetopt prompt_sp
and insert the equivalent sequence into your PS1 string or precmd
function, as described in FAQ 3.23:

    # Skip defining precmd if the PROMPT_SP option is available.
    if ! eval '[[ -o promptsp ]] 2>/dev/null'; then
      function precmd {
        # An efficient version using termcap multi-right:
        print -nP '%B%S%#%s%b'      # Output % or #
        echotc RI $((COLUMNS - 3))
        echo -n '  '                # Output 2 spaces
      }
    fi

If you change the "print -nP" string to be wider, increase the "3" in the
echotc to compensate.  It should always be 2 more than the width of the
print output.

A suggestion I'll throw out in case someone feels like running with it:
Perhaps there should be a %-expando for PS1 that performs the "echotc RI"
of the correct width based on the current %(l..) value (if you see what
I mean), followed by the two spaces.  Suppose that's %P (not necessarily
the best choice, just the first unused letter to come to mind).  Then one
could just do

    PS1="%B%S%#%s%b%P$PS1"

and customize the part to the left of the %P any way they like.  Or %P
could take an "argument" like %D does, if that would be easier:

    PS1=%P{%B%S%#%s%b}$PS1"

Any thoughts from the -workers on that?



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