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

Re: Why does zsh clear to end-of-screen after prompt?



Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote on Fri, 25 Aug 2023
at 20:18:01 EDT in <CAH+w=7ZQaJgvk=wLX5mVEC4XR3AP1kxZU+t6O88PZFAZ6p6w9Q@xxxxxxxxxxxxxx>:

> This happens because ZLE is a mult-line editor and also because
> completion uses the space under the editor area to display lists etc.
> If the screen were not cleared, text being edited could mingle with
> the screen contents already present.

Ugh. I suppose it would be too much to ask that it not do this in the (for me) 90+% case where neither completion nor multi-line editing have been used?

Or only to clear as many lines as have been used, rather than to end-of-screen?

Or a knob to just not clear it and let the user deal with the fallout?

I was optimistic that

   setopt SINGLE_LINE_ZLE 

would solve this, but it does not.

Oddly

  setopt noZLE

does so, but it's a worse user experience than TERM=dumb.
At least with TERM=dumb I get up/down arrow, even if the editing is not quite right and overlaps the prompt in weird ways.


> > How can I get cursor positining to work without forgoing, e.g., line editing?
> 
> You can try something like this:
> 
> PS1=$'%{\e[H%}'$PS1$'%{\e[K%}'

Bah. I mean, yeah, that works, but it feels fairly not-great.

In case it wasn't apparent, the use case is I had a small ad hoc script that produced ~20 lines of key/value output and sometimes the values change and I'd like to keep them in the same position on the screen and just overwrite themselves when they change if I rerun the script with up-arrow/RET.

I guess another way is this:

OPS1="$PS1"	       # save it for idempotency later
PS1=$'%{\e[40H%}'$OPS1
echo '\e[H'; seq 1 20

which, for an 80x48 window, gives 8 lines for editing and commands that don't do any positioning, and leaves the top 40 lines for stuff that's prefixed by CSI H homing to the top-left. Maybe this is an acceptable balance, I dunno.

> There are also games to be played with save_cursor and restore_cursor,
> e.g., a command that wants to control the screen appearance could move
> to a position, save_cursor, and then move to the end of the screen, if
> the prompt were then programmed to start with a restore_cursor -- but
> you still have to be careful about that "start in the leftmost column"
> and deal with avoiding the restore if the last command didn't save.

Yeah, this feels even more...antithetical to the simplicity I was desiring.
Honestly it feels like just using bash for this particular one-off is the easiest way out :(

It seems to me, also, that the documentation could use some improvement on this point, but perhaps it is so obscure that it is going to be hard to find a good place to insert a straightforward discussion of this concern. If this thread doesn't reach any better resolution I'll do some thinking about ways to improve that.

Thanks, Bart.

--
jhawk@xxxxxxxxxxxx
John Hawkinson




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