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

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



On Fri, Aug 25, 2023 at 12:53 PM John Hawkinson <jhawk@xxxxxxxxxxxx> wrote:
>
> When I reposition the cursor to the top left corner of the screen (or anywhere), as with ESC [ H, when zsh prints a prompt it clears from the prompt to the end of the screen, oblitering any text on the screen already, which defeats the point of my cursor positioning.

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.

The clear-to-end-of-screen is actually printed BEFORE the prompt is
output, to make sure the prompt itself doesn't commingle with
anything, and the prompt always expects to be started in the leftmost
column or editing will be confused.

> 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%}'

However, this only works because the cursor positioning is part of the
prompt string.  If you try to move the cursor with a command like in
your "echo" example, zle is still going to erase the whole screen at
and below the line where the cursor is positioned when the command
finishes.

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.




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