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

Re: Possible bug to RPROMPT



On Aug 1,  5:20am, Felipe G. Silveira wrote:
}
} Since I setup my PROMPT so the information comes in one line and my cursor
} below it, I was trying to align the RPROMPT to always appear 1 line before
} where it generally is printed.

If I understand correctly, what you want is:

First_line_of_PROMPT_here...................................RPROMPT_here
Second_line.cursor

where I have used dots in place of whitespace in case of line wrap.

} so after some tinkering, I decided to try some escape commands:
} 
} PROMPT=$'\e[s'$'\e[1A''< [clock] ''$'\e[1B'$'\e[u'

You have the right general idea (though there are too many quotes in
that line) but have overlooked the %{ and %} prompt formats, which help
ZLE to compute the start and end positions of the prompt text.  If you
move the cursor with terminal escapes while inside the prompt, you must
wrap the "zero width" parts in %{...%} so ZLE won't count them when it
calculates the number of columns occupied by the prompt.

In the case of your specific desire, you can probably get away with
using only vertical motions (no save/restore of cursor) like so:

PROMPT="First_line_of_PROMPT_here"$'\n'"Second_line "
RPROMPT=$'%{\e[1A%}'"RPROMPT_here"$'%{\e[1B%}'

This just says that the right prompt begins with a zero-width motion,
which happens to be "up one line", and ends with another zero-width
motion, "down one line".  Because ZLE only cares about the horizontal
position for its calculations, as long as you make sure the cursor
starts and ends on the same line it all works out.

Note, though, that if "First_line_of_PROMPT_here" is wide enough to
overlap with "RPROMPT_here", the RPROMPT will write over it.  Also,
the TRANSIENT_RPROMPT option will have no effect because the text is
one line above where ZLE expects it to be.

For a more complicated example of a prompt that looks like what you
want but does not use RPROMPT to accomplish it, read the "Prompt Themes"
section of "man zshcontrib" and then try "prompt -h bart".



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