zsh-users
 help / color / mirror / code / Atom feed
* Outputting colored zsh prompts from an external script
@ 2013-03-24 19:23 seanh
  2013-03-24 21:48 ` Christian Neukirchen
  0 siblings, 1 reply; 8+ messages in thread
From: seanh @ 2013-03-24 19:23 UTC (permalink / raw)
  To: zsh-users

Hey,

I'm trying to write a Python script to handle my zsh prompts. The idea
is to call my Python script from my zshrc to define my PROMPT and
RPROMPT:

    PROMPT='$(zshprompt.py left)'
    RPROMPT='$(zshprompt.py right --last-exit-status=$?)'

(I also want to make it fall back on a default, pure-zsh prompt if
zshprompt.py returns a non-zero exist status, but that's to do later.)

The Python script then prints whatever it wants to stdout to form the
prompt and right prompt. The full code is here:

    https://gist.github.com/seanh/5233082

This all works fine, I've got my Python script ouptutting a nicely
truncated current working directory, name of the active virtualenv if
any, name of the current git branch if in a git repo, exit status of the
last command if non-zero, and user@host if using an ssh connection.

The problem comes when I try to introduce colors into the prompts. As
you can see from the Python code it's printing out ANSI escape sequences
to color the prompts, but this messes up the positioning of the right
prompt and cursor in zsh. Here's a screenshot showing the problem:

https://www.dropbox.com/s/4nqs7ceojmqqtmi/Screenshot%20from%202013-03-24%2020%3A01%3A21.png

The cursor has been pushed right along to left edge of the terminal
(instead of being after the left prompt as it should be), and the right
prompt seems to get pushed further and further to the left as more ANSI
escape codes come into the prompts.

Here's a screenshot of the same thing but with zshprompt.py's color()
function disabled, so you can see where everything's supposed to be:

https://www.dropbox.com/s/dg0p9741ip7zx1m/Screenshot%20from%202013-03-24%2020%3A00%3A35.png

I also tried getting zshprompt.py to print out zsh color codes like
%{$fg[red]%}FOO%{$reset_color%}, but zsh doesn't seem to interpret these
when they're printed by zshprompt.py, it just prints them out into the
prompts literally. I tried various zsh options with this, such as
setopt promptpercent and setopt promptsubst, and tried various other ways of
calling the Python script, such as within double-quotes or back-ticks
instead of single-quotes, or without any quotes at all. Nothing worked.

Any idea how I can do colour prompts from within my Python script?

Thanks


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-03-29 15:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-24 19:23 Outputting colored zsh prompts from an external script seanh
2013-03-24 21:48 ` Christian Neukirchen
2013-03-25 13:05   ` seanh
2013-03-25 15:29     ` Bart Schaefer
2013-03-25 19:40       ` seanh
2013-03-28 20:26         ` seanh
2013-03-28 21:14           ` TJ Luoma
2013-03-29 15:07           ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).