zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: John Hawkinson <jhawk@alum.mit.edu>
Cc: zsh-users@zsh.org
Subject: Re: Why does zsh clear to end-of-screen after prompt?
Date: Fri, 25 Aug 2023 17:18:01 -0700	[thread overview]
Message-ID: <CAH+w=7ZQaJgvk=wLX5mVEC4XR3AP1kxZU+t6O88PZFAZ6p6w9Q@mail.gmail.com> (raw)
In-Reply-To: <ZOkGi5f6hPuk_1-b@louder-room.local>

On Fri, Aug 25, 2023 at 12:53 PM John Hawkinson <jhawk@alum.mit.edu> 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.


  reply	other threads:[~2023-08-26  0:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-25 19:52 John Hawkinson
2023-08-26  0:18 ` Bart Schaefer [this message]
2023-08-26  0:59   ` John Hawkinson
2023-08-26  1:39     ` Bart Schaefer
2023-08-27  8:34     ` Roman Perepelitsa
2023-08-27 15:36       ` Grant Taylor
2023-08-27 16:02         ` Roman Perepelitsa
2023-08-27 18:55           ` Grant Taylor
2023-09-09 23:23     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7ZQaJgvk=wLX5mVEC4XR3AP1kxZU+t6O88PZFAZ6p6w9Q@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=jhawk@alum.mit.edu \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).