zsh-users
 help / color / mirror / code / Atom feed
* Cursor save/restore is redrawing over existing output
@ 2020-12-18  2:25 Seth House
  2020-12-18  5:40 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Seth House @ 2020-12-18  2:25 UTC (permalink / raw)
  To: zsh-users

Hello. I'm seeing Zsh behavior I was hoping someone could shed some
light on.

When I save the cursor position, then output something, and then restore
the cursor position the text that was output is redrawn over (blanked).

To reproduce:

% exec zsh -d -f
% printf '\e[s'
% printf 'Hello, world\n'
Hello, world
% printf '\e[u'

Everything prints as expected until the final printf. After that the
cursor does indeed move, however everything below the first printf is
erased.

In contrast with Bash and Busybox sh the cursor position moves but the
contents of the terminal are not changed. Is this intended behavior or
am I missing something else?

Using xterm on Fedora.

% zsh --version
zsh 5.8 (x86_64-redhat-linux-gnu)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Cursor save/restore is redrawing over existing output
  2020-12-18  2:25 Cursor save/restore is redrawing over existing output Seth House
@ 2020-12-18  5:40 ` Bart Schaefer
  2020-12-18  6:15   ` Seth House
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2020-12-18  5:40 UTC (permalink / raw)
  To: Seth House; +Cc: Zsh Users

On Thu, Dec 17, 2020 at 6:25 PM Seth House <seth@eseth.com> wrote:
>
> Everything prints as expected until the final printf. After that the
> cursor does indeed move, however everything below the first printf is
> erased.

The ZLE editor presumes that the prompt is always printed at the
bottom of any output and clears the screen so that there's nothing to
interfere with completion listings and other messages that the editor
may want to display below that prompt.

Depending on why you're attempting to save and restore the cursor,
there may be a ZLE-compatible way to accomplish what you want.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Cursor save/restore is redrawing over existing output
  2020-12-18  5:40 ` Bart Schaefer
@ 2020-12-18  6:15   ` Seth House
  2020-12-18  8:44     ` Roman Perepelitsa
  0 siblings, 1 reply; 5+ messages in thread
From: Seth House @ 2020-12-18  6:15 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

On Thu, Dec 17, 2020 at 09:40:12PM -0800, Bart Schaefer wrote:
> The ZLE editor presumes that the prompt is always printed at the
> bottom of any output and clears the screen

Ah ha! Thank you, that makes total sense. And you're right -- if
I disable zle then the behavior matches Bash and sh. I haven't delved
into zle yet so I'll go through those docs now.

> Depending on why you're attempting to save and restore the cursor,
> there may be a ZLE-compatible way to accomplish what you want.

I'm experimenting with the (probably dumb) idea of only displaying the
output from a single command at a time for a rudimentary TUI-like-thing.

For example, if you type `ls` the directory listing appears below the
prompt as normal, but then the cursor returns to the original row and
clears the prompt so the next command you type, say `uptime`, outputs as
normal but also clears the directory listing output. The idea being that
you can run several commands in succession without moving the cursor or
scrolling the terminal.

Some of Zsh's completions have a similar look-and-feel to what I'm after
so that may be a better tree to bark up but for now I'm just
experimenting. That said, I'd very much appreciate any suggestions for
where else to look.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Cursor save/restore is redrawing over existing output
  2020-12-18  6:15   ` Seth House
@ 2020-12-18  8:44     ` Roman Perepelitsa
  2020-12-19 20:29       ` Seth House
  0 siblings, 1 reply; 5+ messages in thread
From: Roman Perepelitsa @ 2020-12-18  8:44 UTC (permalink / raw)
  To: Seth House; +Cc: Bart Schaefer, Zsh Users

On Fri, Dec 18, 2020 at 7:16 AM Seth House <seth@eseth.com> wrote:
>
> I'm experimenting with the (probably dumb) idea of only displaying the
> output from a single command at a time for a rudimentary TUI-like-thing.
>
> For example, if you type `ls` the directory listing appears below the
> prompt as normal, but then the cursor returns to the original row and
> clears the prompt so the next command you type, say `uptime`, outputs as
> normal but also clears the directory listing output. The idea being that
> you can run several commands in succession without moving the cursor or
> scrolling the terminal.

I also prefer my prompt to stay at a fixed position. However, having
command output *below* prompt is not a good idea. I've listed a few
reasons in https://github.com/romkatv/powerlevel10k-media/issues/2#issuecomment-725415740.
What I do instead is put prompt *at the bottom* and make it stay
there. The latter is a bit tricky because completion listings can push
prompt up. With a bit of work this can be changed so that completion
listings appear above prompt in a sort of temporary overlay. This
setup is quite ergonomic as it allows you to position your terminal
window so that important information (prompt and the end of the output
of the last command) is always at the same position. You can see it in
action here: https://asciinema.org/a/372068. You can also try it in
docker: https://github.com/romkatv/zsh4humans/tree/v5#try-it-in-docker.

Roman.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Cursor save/restore is redrawing over existing output
  2020-12-18  8:44     ` Roman Perepelitsa
@ 2020-12-19 20:29       ` Seth House
  0 siblings, 0 replies; 5+ messages in thread
From: Seth House @ 2020-12-19 20:29 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Bart Schaefer, Zsh Users

On Fri, Dec 18, 2020 at 09:44:45AM +0100, Roman Perepelitsa wrote:
> What I do instead is put prompt *at the bottom* and make it stay
> there.

That is *extremely* cool. I had the same thoughts as you in your
well-explained rationale but I didn't think that result would be
possible with existing shells. That really blows me away.

Thanks for those links. That will easily be my weekend leisure time. :D



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-19 20:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-18  2:25 Cursor save/restore is redrawing over existing output Seth House
2020-12-18  5:40 ` Bart Schaefer
2020-12-18  6:15   ` Seth House
2020-12-18  8:44     ` Roman Perepelitsa
2020-12-19 20:29       ` Seth House

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).