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

Incorrect cursor position when ZLE_RPROMPT_INDENT=0 (with a fix)



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.


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