Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: draw prompt on the correct line after window change
- X-seq: zsh-workers 44525
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: PATCH: draw prompt on the correct line after window change
- Date: Mon, 15 Jul 2019 19:20:08 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=FX0aDxDq8t6UoAqfr6Yvz8QWiJGsK77+Fxz/YN8qNfw=; b=IYSaeIRN06bz4z0u5mRNyhyu4NkR/iKCHN2d+WKDDu0oFBWLpXEqcQDWYbAwwB6F5C /oVn1Z2IUTh9eNJozKsHPOp1IDDOmZUCmvTTotIRBRVlQ/FSM/o2EwrQpepjwVQBefUB wzpUheQQaD4t/gg2FZxEn1+7YaKKSFIyW/yGUfMqyhPQ3pjXxCINQhcRSahQ2UFDXtVd Wl/uc5LExE6XAbo24yoXrCbFovio5s6dNk9olh1Bj3jLnYDWzJHlrIN0pimDoAJnGQ0s UqwxWD5O8/iPDcdEeXwjUYc/r6QpiRLgErIkM1c0+Oq/iWzC7K+gB/FWVj1DHYSivgp9 rhKg==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Many terminals reflow text when the window is resized. When the height
of the prompt changes as a result of this reflowing, ZSH draws the
updated prompt on the wrong line. This can lead to some parts of the
prompt not being erased, or to the disappearance of lines prior to the
prompt.
There are many ways to reproduce this issue. Here are a couple. Both
require terminals that reflow text when the window is resized.
1. Run `zsh -df`, hit <enter> a few times, then type
`xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` (don't hit <enter>).
OR
2. Run `PROMPT="${(pl.$COLUMNS..-.)}%f"$'\n> ' zsh -df`
and hit <enter> a few times.
Now try resizing the terminal window back and forth causing lines to
wrap and unwrap. Terminal content before the last prompt will be
erased one line at a time.
This patch cannot handle the case when the terminal window is being
resized while the first prompt line is outside the terminal window.
The content of the viewport will be correct but scrolling the terminal
window up will reveal some mess up there. ZSH before this patch also
fails in this case although it creates a different mess.
The change is conservative. The new code triggers only on window
resize and not, for example, on redisplay. This reduces the chance
that it'll break something that isn't currently broken.
I've tested this code only on GNOME Terminal. Before I go testing on a
dozen different terminals I'd like to get some feedback. Anything I'm
missing? Anything tricky to look out for?
The patch is attached to the email. You can also see it in
https://github.com/zsh-users/zsh/compare/master...romkatv:fix-winchanged.
Roman.
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index 85e55e0d4..249d75d71 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -660,6 +660,7 @@ static int more_start, /* more text before start of screen? */
lpromptw, rpromptw, /* prompt widths on screen */
lpromptwof, /* left prompt width with real end position */
lprompth, /* lines taken up by the prompt */
+ cursorsaved, /* whether prompt start position was saved */
rprompth, /* right prompt height */
vcs, vln, /* video cursor position column & line */
vmaxln, /* video maximum number of lines */
@@ -994,6 +995,7 @@ zrefresh(void)
int remetafy; /* flag that zle line is metafied */
zattr txtchange; /* attributes set after prompts */
int rprompt_off = 1; /* Offset of rprompt from right of screen */
+ int savecursorneeded = 0; /* prompt start position needs to be saved */
struct rparams rpms;
#ifdef MULTIBYTE_SUPPORT
int width; /* width of wide character */
@@ -1133,7 +1135,13 @@ zrefresh(void)
zsetterm();
#ifdef TIOCGWINSZ
if (winchanged) {
- moveto(0, 0);
+ if (cursorsaved) {
+ tcout(TCRESTRCURSOR);
+ zputc(&zr_cr);
+ vln = vcs = 0;
+ } else {
+ moveto(0, 0);
+ }
t0 = olnct; /* this is to clear extra lines even when */
winchanged = 0; /* the terminal cannot TCCLEAREOD */
listshown = 0;
@@ -1164,7 +1172,16 @@ zrefresh(void)
if (termflags & TERM_SHORT)
vcs = 0;
else if (!clearflag && lpromptbuf[0]) {
- zputs(lpromptbuf, shout);
+ cursorsaved = 0;
+ if (tccan(TCSAVECURSOR) && tccan(TCRESTRCURSOR)) {
+ if (!(termflags & TERM_SHORT)) {
+ savecursorneeded = 1;
+ } else if (lprompth <= rwinh) {
+ tcout(TCSAVECURSOR);
+ cursorsaved = 1;
+ }
+ }
+ zputs(lpromptbuf, shout);
if (lpromptwof == winw)
zputs("\n", shout); /* works with both hasam and !hasam */
} else {
@@ -1737,6 +1754,12 @@ individually */
clearf = 0;
oput_rpmpt = put_rpmpt;
+ if (savecursorneeded && lprompth + nlnct <= rwinh) {
+ moveto(1 - lprompth, 0);
+ tcout(TCSAVECURSOR);
+ cursorsaved = 1;
+ }
+
/* move to the new cursor position */
moveto(rpms.nvln, rpms.nvcs);
Messages sorted by:
Reverse Date,
Date,
Thread,
Author