Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Incorrect cursor position when ZLE_RPROMPT_INDENT=0 (with a fix)
- X-seq: zsh-workers 44320
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Incorrect cursor position when ZLE_RPROMPT_INDENT=0 (with a fix)
- Date: Sun, 19 May 2019 17:38:16 +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=jJg9L8rFzfYqPwzAH7D2Ar8Bk4ezZcrIReKqI+izbMI=; b=ID5fjEp/8P7HNorokXgT9gh3NrONG9AJJuWwb5Q0XxD+xUo1+bhOlMqoWOghYb4/lv OH0OwmtUSN+F5wy9lSPVUZRUHpc3HbQgMo7Ci+DKEO512yahcAaONUwL7u0dqc5j68w6 TQHxGRKXTM6TnjGmUcT5lC93BiOA1LiZNP9HScmuDDhehAVbEhTFjHPGQ/kFZa/0mSZw ZJomE1IIIwsa5H1w3bPBwxJQqUOynZxeJ4Q1zn3sleH3R0RcCpyJyRDc7O9IYiWBEb0S nPaKRTT2ZJ3Gy/9GCBa5lyJKniLTD9nCCUBbDefHazzSvHADG4rbZ19hLN/b1XxkFMzl A08Q==
- 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
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