Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Graceful hiding of $RPROMPT
- X-seq: zsh-users 14672
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Graceful hiding of $RPROMPT
- Date: Sun, 20 Dec 2009 10:17:27 -0800
- In-reply-to: <2d460de70912200133t4e1dcc72l3737395b46b0753e@xxxxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <2d460de70912200133t4e1dcc72l3737395b46b0753e@xxxxxxxxxxxxxx>
On Dec 20, 10:33am, Richard Hartmann wrote:
}
} I am looking for a way to fall back gracefully, i.e. remove more and
} more of $RPROMPT when needed instead of the all or nothing mechanism
} which is in place, now.
This may not be impossible to do in shell code, but I think it's going
to be prohibitively difficult.
Look at Functions/Prompts/prompt_bart_setup. From "prompt -h bart":
The "upper right prompt" looks like:
date time
The fourth color is used for the date, and the first again for the
time. As with RPS1, first the date and then the time disappear as
the upper left prompt grows too wide.
The prompt_bart_precmd function is where the computation of widths is
handled in order to set up the upper right prompt. The complication
you're faced with is computing the width of left prompt plus the width
of the first line of input (which might be in $BUFFER or might be in
$PREBUFFER) *and* doing so every time the contents of $BUFFER change.
There's no single place to intercept buffer changes, so you'll have to
at least override the self-insert widget and probably any other widget
that might insert or delete (e.g., the entire completion suite). Or
set an extremely short TMOUT and have the shell effectively busy-wait
on TRAPARLM to watch for changes, but I can't recommend that.
Another possibility is to embed the right prompt in PS1 rather than
using RPS1 at all. The same width computations in prompt_bart_precmd
would apply; you would use save/restore cursor position escapes in PS1
and wrap output of the right prompt in %{...%} so that the line editor
can't "see" that a right prompt exists at all.
In this scenario you simply type over the right prompt as the input
extends far enough, which might not be visually appealing.
A final possibility is to do something like this:
zle-line-init() { POSTDISPLAY="${(%%):- %D %@}"; zle -R }
zle -N zle-line-init
This puts a prompt-like string at the end of the buffer and scrolls
it away to the right as you type. A drawback here is that you can't
embed any terminal control sequences in POSTDISPLAY, zsh converts them
all to literal characters before output.
So to really get what you want, it'll require hacking the C code in
Src/Zle/zle_refresh.c, function zrefresh. Look for references to
"rpmpt" e.g. the variable "put_rpmpt". A nice touch would be if the
%(l...) mechansim was intelligent about being used in RPS1 and counted
the ZLE buffer as part of "at least N characters have already been
printed".
--
Messages sorted by:
Reverse Date,
Date,
Thread,
Author