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

Re: PROMPT escape sequences



On Oct 7, 11:34pm, Atom Smasher wrote:
}
} PS1='%S%# '

That doesn't just set your prompt to reverse, does it?  Everything you
type after the prompt would be in reverse, too, because you're never
turning "standout mode" off again after turning it on.

Similarly:

} PS1='%{^[[36m%}%# '

This enters cyan coloring mode but does not leave it again.

The prompt itself (the "%" or "#" sign) remains cyan colored, does it not?
Zsh is only responsible for what happens to the characters that are in
the PS1 string, not for any "unbalanced" state you've left things in
after PS1 has been printed.

So the answer to this question is:

} is there a way to set a color at the prompt that doesn't reset to default 
} when i tab-complete?

No, there isn't, because you're relying on the entire prompt being re-
painted every time zsh needs to redraw the line that begins with the
prompt, but ZLE is optimized to use cursor motions and only redraw the
bits of the line that actually need changing.  It has no idea what the
color settings are at any given position on the terminal, so it can't
restore color; it only knows what the non-zero-width characters are.

It "works" for %S because of a quirk in the way some terminals (xterm
included) implement "standout mode", not because of anything zsh does
differently.  On a different terminal/emulator (or possibly even just
with different termcap/terminfo definitions) you're likely to see %S
behaving the same way you now see cyan.

You can "unsetopt alwayslastprompt" so that zsh does not return to the
previous prompt after completing, but you may find that unsatisfactory
for other reasons.



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