zsh-workers
 help / color / mirror / code / Atom feed
* Incorrect cursor position when ZLE_RPROMPT_INDENT=0 (with a fix)
@ 2019-05-19 15:38 Roman Perepelitsa
  2019-05-19 15:41 ` Roman Perepelitsa
  2019-05-19 17:04 ` Bart Schaefer
  0 siblings, 2 replies; 28+ messages in thread
From: Roman Perepelitsa @ 2019-05-19 15:38 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 3170 bytes --]

To reproduce:

ZLE_RPROMPT_INDENT=0
PROMPT=12
RPROMPT=3

Expected behavior: The cursor is positioned after ‘2’.
Actual behavior: The cursor is positioned on ‘2’.

The following patch fixes this issue.

diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index 1f293845f..9c650d3ae 100644--- a/Src/Zle/zle_refresh.c+++
b/Src/Zle/zle_refresh.c
@@ -1678,7 +1678,7 @@ zrefresh(void)

         moveto(0, winw - rprompt_off - rpromptw);
         zputs(rpromptbuf, shout);-        vcs = winw - rprompt_off;+
      vcs = winw - (rprompt_off ? rprompt_off : 1);
     /* reset character attributes to that set by the main prompt */
         txtchange = pmpt_attr;
         /*
@@ -2159,7 +2159,7 @@ moveto(int ln, int cl)
     const REFRESH_ELEMENT *rep;

     if (vcs == winw) {-    if (rprompt_indent == 0 && tccan(TCLEFT))
{+    if (0) {
       tc_leftcurs(1);
       vcs--;
     } else {

There is now an if-else with 0 as the condition. I’ve posted the diff this
way to make it clearer what I’d actually changed. The if-else can, of
course, be replaced with a single block of code (what used to be under else),
which produces a larger diff due to indentation changes. ZSH source code
uses a mixture of tabs and spaces, so I’m not sure if I deindented it right.

diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index 1f293845f..85f9d9305 100644--- a/Src/Zle/zle_refresh.c+++
b/Src/Zle/zle_refresh.c
@@ -1678,7 +1678,7 @@ zrefresh(void)

         moveto(0, winw - rprompt_off - rpromptw);
         zputs(rpromptbuf, shout);-        vcs = winw - rprompt_off;+
      vcs = winw - (rprompt_off ? rprompt_off : 1);
     /* reset character attributes to that set by the main prompt */
         txtchange = pmpt_attr;
         /*
@@ -2159,25 +2159,20 @@ moveto(int ln, int cl)
     const REFRESH_ELEMENT *rep;

     if (vcs == winw) {-    if (rprompt_indent == 0 && tccan(TCLEFT))
{-      tc_leftcurs(1);-      vcs--;-    } else {-        vln++, vcs =
0;-        if (!hasam) {-        zputc(&zr_cr);-
zputc(&zr_nl);-        } else {-        if ((vln < nlnct) && nbuf[vln]
&& nbuf[vln]->chr)-            rep = nbuf[vln];-        else-
  rep = &zr_sp;-        zputc(rep);-        zputc(&zr_cr);-        if
((vln < olnct) && obuf[vln] && obuf[vln]->chr)-            *obuf[vln]
= *rep;-        }-    }+    vln++, vcs = 0;+    if (!hasam) {+
zputc(&zr_cr);+    zputc(&zr_nl);+    } else {+    if ((vln < nlnct)
&& nbuf[vln] && nbuf[vln]->chr)+        rep = nbuf[vln];+    else+
   rep = &zr_sp;+    zputc(rep);+    zputc(&zr_cr);+    if ((vln <
olnct) && obuf[vln] && obuf[vln]->chr)+        *obuf[vln] = *rep;+
}
     }

     if (ln == vln && cl == vcs)

The same thing on github:
https://github.com/zsh-users/zsh/compare/master…romkatv:rprompt-indent
<https://github.com/zsh-users/zsh/compare/master...romkatv:rprompt-indent>.

I’ve verified that it works correctly with ZLE_RPROMPT_INDENT={0,1,2} in
GNOME Terminal on Ubuntu 18.04. The cursor gets positioned in the right
place and there is no weird behavior in completion menu or other multi-line
ZLE situations.

Roman.

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

end of thread, other threads:[~2019-05-28 14:27 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-19 15:38 Incorrect cursor position when ZLE_RPROMPT_INDENT=0 (with a fix) Roman Perepelitsa
2019-05-19 15:41 ` Roman Perepelitsa
2019-05-19 17:04 ` Bart Schaefer
2019-05-19 17:34   ` Roman Perepelitsa
2019-05-19 18:09     ` Roman Perepelitsa
2019-05-19 18:51       ` Roman Perepelitsa
2019-05-19 20:12         ` Bart Schaefer
2019-05-19 21:07           ` Roman Perepelitsa
2019-05-20  8:21             ` Yannic Schröder
2019-05-20  8:36               ` Roman Perepelitsa
2019-05-20 10:21                 ` Charles Blake
2019-05-20 10:46                   ` Roman Perepelitsa
2019-05-20 11:06                     ` Daniel Shahaf
2019-05-20 11:07                     ` Charles Blake
2019-05-20 11:11                       ` Peter Stephenson
2019-05-20 11:32                       ` Roman Perepelitsa
2019-05-20 12:41                     ` Charles Blake
2019-05-20 13:16                       ` Roman Perepelitsa
     [not found]                         ` <CAKiz1a-nOkAe42JoxFRgMJ+LXZ3fgMxqgwNZOW+2Y45oqzu8hA@mail.gmail.com>
2019-05-20 13:55                           ` Roman Perepelitsa
2019-05-23  5:48                             ` Roman Perepelitsa
2019-05-23 21:36                               ` Daniel Shahaf
2019-05-23 22:52                                 ` Roman Perepelitsa
2019-05-24 12:18                                   ` Daniel Shahaf
2019-05-27 15:36                                     ` Roman Perepelitsa
2019-05-27 21:51                                       ` Peter Stephenson
2019-05-28  8:44                                         ` Peter Stephenson
2019-05-28  8:46                                           ` Roman Perepelitsa
2019-05-28 14:26                                         ` Bart Schaefer

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