zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] complist: Turn off colors before clearing to end of line
@ 2021-08-17  8:57 Marlon Richert
  2021-08-18  4:07 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Marlon Richert @ 2021-08-17  8:57 UTC (permalink / raw)
  To: Zsh hackers list

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

Try the following without and with the patch, to see what this fixes:

% zmodload zsh/complist
% autoload compinit
% compinit
% bindkey '^I' menu-select
% ping -<TAB><TAB>
<Default selection highlight (reverse video) stops at the end of the match.>
% zstyle '*' list-colors 'ma=97;44'
% ping -<TAB><TAB>
<Without the patch, when changing selection, highlight continues until
end of line.>
<With the patch, it stops at the end of the match, just like the default.>

[-- Attachment #2: 0001-complist-Turn-off-colors-before-clearing-to-end-of-l.txt --]
[-- Type: text/plain, Size: 1174 bytes --]

From 555dbb68a30bef5e224a5e01b9c3210884fd4a61 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlonrichert@users.noreply.github.com>
Date: Tue, 17 Aug 2021 11:43:06 +0300
Subject: [PATCH] complist: Turn off colors before clearing to end of line

---
 Src/Zle/complist.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 353cb3562..4d015991f 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -1306,6 +1306,7 @@ compprintfmt(char *fmt, int n, int dopr, int doesc, int ml, int *stop)
     if (dopr) {
         if (!(cc % zterm_columns))
             fputs(" \010", shout);
+        zcoff();
         if (mlbeg >= 0 && tccan(TCCLEAREOL))
             tcout(TCCLEAREOL);
     }
@@ -1785,14 +1786,14 @@ clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width)
 	    zcputs(g->name, COL_DU);
 	else
 	    subcols = putmatchcol(g->name, m->disp);
-	if (subcols)
+	if (subcols) {
 	    ret = clprintfmt(m->disp, ml);
-	else {
+	    zcoff();
+	} else {
 	    compprintfmt(m->disp, 0, 1, 0, ml, &stop);
 	    if (stop)
 		ret = 1;
 	}
-	zcoff();
     } else {
 	int mx, modec;
 
-- 
2.32.0


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

* Re: [PATCH] complist: Turn off colors before clearing to end of line
  2021-08-17  8:57 [PATCH] complist: Turn off colors before clearing to end of line Marlon Richert
@ 2021-08-18  4:07 ` Bart Schaefer
  2021-08-19 19:28   ` Marlon Richert
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2021-08-18  4:07 UTC (permalink / raw)
  To: Marlon Richert; +Cc: Zsh hackers list

On Tue, Aug 17, 2021 at 1:58 AM Marlon Richert <marlon.richert@gmail.com> wrote:
>
> <Without the patch, when changing selection, highlight continues until
> end of line.>
> <With the patch, it stops at the end of the match, just like the default.>

And the zcoff() is never needed in the compprintfmt() branch?


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

* Re: [PATCH] complist: Turn off colors before clearing to end of line
  2021-08-18  4:07 ` Bart Schaefer
@ 2021-08-19 19:28   ` Marlon Richert
  2021-08-20  6:39     ` Marlon Richert
  0 siblings, 1 reply; 5+ messages in thread
From: Marlon Richert @ 2021-08-19 19:28 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

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

On Wed, Aug 18, 2021 at 7:07 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Tue, Aug 17, 2021 at 1:58 AM Marlon Richert <marlon.richert@gmail.com> wrote:
> >
> > <Without the patch, when changing selection, highlight continues until
> > end of line.>
> > <With the patch, it stops at the end of the match, just like the default.>
>
> And the zcoff() is never needed in the compprintfmt() branch?

Hm, good point. How about this patch instead?

[-- Attachment #2: 0001-complist-Turn-off-colors-before-clearing-to-end-of-l.txt --]
[-- Type: text/plain, Size: 1174 bytes --]

From 555dbb68a30bef5e224a5e01b9c3210884fd4a61 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlonrichert@users.noreply.github.com>
Date: Tue, 17 Aug 2021 11:43:06 +0300
Subject: [PATCH] complist: Turn off colors before clearing to end of line

---
 Src/Zle/complist.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 353cb3562..4d015991f 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -1306,6 +1306,7 @@ compprintfmt(char *fmt, int n, int dopr, int doesc, int ml, int *stop)
     if (dopr) {
         if (!(cc % zterm_columns))
             fputs(" \010", shout);
+        zcoff();
         if (mlbeg >= 0 && tccan(TCCLEAREOL))
             tcout(TCCLEAREOL);
     }
@@ -1785,14 +1786,14 @@ clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width)
 	    zcputs(g->name, COL_DU);
 	else
 	    subcols = putmatchcol(g->name, m->disp);
-	if (subcols)
+	if (subcols) {
 	    ret = clprintfmt(m->disp, ml);
-	else {
+	    zcoff();
+	} else {
 	    compprintfmt(m->disp, 0, 1, 0, ml, &stop);
 	    if (stop)
 		ret = 1;
 	}
-	zcoff();
     } else {
 	int mx, modec;
 
-- 
2.32.0


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

* Re: [PATCH] complist: Turn off colors before clearing to end of line
  2021-08-19 19:28   ` Marlon Richert
@ 2021-08-20  6:39     ` Marlon Richert
  2021-08-20 23:42       ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Marlon Richert @ 2021-08-20  6:39 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

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

On Thu, Aug 19, 2021 at 10:28 PM Marlon Richert
<marlon.richert@gmail.com> wrote:
>
> On Wed, Aug 18, 2021 at 7:07 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
> >
> > On Tue, Aug 17, 2021 at 1:58 AM Marlon Richert <marlon.richert@gmail.com> wrote:
> > >
> > > <Without the patch, when changing selection, highlight continues until
> > > end of line.>
> > > <With the patch, it stops at the end of the match, just like the default.>
> >
> > And the zcoff() is never needed in the compprintfmt() branch?
>
> Hm, good point. How about this patch instead?

Whoops! It looks like I sent the same patch again. Here is now the one
I actually meant to send. Apologies for the confusion.

[-- Attachment #2: 0001-complist-Turn-off-colors-before-clearing-to-end-of-l.txt --]
[-- Type: text/plain, Size: 2915 bytes --]

From ded9c40e54a3efd458cd78d3b0796bac8206f9af Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlonrichert@users.noreply.github.com>
Date: Thu, 19 Aug 2021 17:02:10 +0300
Subject: [PATCH] complist: Turn off colors before clearing to end of line

---
 Src/Zle/complist.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 353cb3562..cccf5d489 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -603,6 +603,16 @@ zcoff(void)
 	zcputs(NULL, COL_NO);
 }
 
+/* Clear to end of line, if possible and necessary. */
+static void
+cleareol()
+{
+    if (mlbeg >= 0 && tccan(TCCLEAREOL)) {
+        if (*last_cap)
+            zcoff();    /* If we used colors, prevent them from bleeding. */
+        tcout(TCCLEAREOL);
+	}
+}
 
 static void
 initiscol(void)
@@ -670,8 +680,7 @@ clprintfmt(char *p, int ml)
 	doiscol(i++);
 	cc++;
 	if (*p == '\n') {
-	    if (mlbeg >= 0 && tccan(TCCLEAREOL))
-		tcout(TCCLEAREOL);
+	    cleareol();
 	    cc = 0;
 	}
 	if (ml == mlend - 1 && (cc % zterm_columns) == zterm_columns - 1)
@@ -693,8 +702,7 @@ clprintfmt(char *p, int ml)
 	    !--mrestlines && (ask = asklistscroll(ml)))
 	    return ask;
     }
-    if (mlbeg >= 0 && tccan(TCCLEAREOL))
-	tcout(TCCLEAREOL);
+    cleareol();
     return 0;
 }
 
@@ -1047,8 +1055,7 @@ compprintnl(int ml)
 {
     int ask;
 
-    if (mlbeg >= 0 && tccan(TCCLEAREOL))
-	tcout(TCCLEAREOL);
+    cleareol();
     putc('\n', shout);
 
     if (mscroll && !--mrestlines && (ask = asklistscroll(ml)))
@@ -1263,8 +1270,8 @@ compprintfmt(char *fmt, int n, int dopr, int doesc, int ml, int *stop)
 	    if ((cc >= zterm_columns - 2 || cchar == ZWC('\n')) && stat)
 		dopr = 2;
 	    if (cchar == ZWC('\n')) {
-		if (dopr == 1 && mlbeg >= 0 && tccan(TCCLEAREOL))
-		    tcout(TCCLEAREOL);
+		if (dopr == 1)
+		    cleareol();
 		l += 1 + ((cc - 1) / zterm_columns);
 		cc = 0;
 	    }
@@ -1306,8 +1313,7 @@ compprintfmt(char *fmt, int n, int dopr, int doesc, int ml, int *stop)
     if (dopr) {
         if (!(cc % zterm_columns))
             fputs(" \010", shout);
-        if (mlbeg >= 0 && tccan(TCCLEAREOL))
-            tcout(TCCLEAREOL);
+        cleareol();
     }
     if (stat && n)
 	mfirstl = -1;
@@ -1338,8 +1344,8 @@ compzputs(char const *s, int ml)
 	    c = *s;
 	s++;
 	putc(c, shout);
-	if (c == '\n' && mlbeg >= 0 && tccan(TCCLEAREOL))
-	    tcout(TCCLEAREOL);
+	if (c == '\n')
+	    cleareol();
 	if (mscroll && (++col == zterm_columns || c == '\n')) {
 	    ml++;
 	    if (!--mrestlines && (ask = asklistscroll(ml)))
@@ -1692,8 +1698,7 @@ compprintlist(int showall)
 
 	    lastlistlen = listdat.nlines;
 	} else if ((nl = listdat.nlines + nlnct - 1) < zterm_lines) {
-	    if (mlbeg >= 0 && tccan(TCCLEAREOL))
-		tcout(TCCLEAREOL);
+	    cleareol();
 	    tcmultout(TCUP, TCMULTUP, nl);
 	    showinglist = -1;
 
-- 
2.33.0


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

* Re: [PATCH] complist: Turn off colors before clearing to end of line
  2021-08-20  6:39     ` Marlon Richert
@ 2021-08-20 23:42       ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2021-08-20 23:42 UTC (permalink / raw)
  To: Marlon Richert; +Cc: Zsh hackers list

Thanks!  Except that some indentation looks odd in the first hunk, I
think this is probably fine.

On Thu, Aug 19, 2021 at 11:40 PM Marlon Richert
<marlon.richert@gmail.com> wrote:
>
> On Thu, Aug 19, 2021 at 10:28 PM Marlon Richert
> <marlon.richert@gmail.com> wrote:
> >
> > On Wed, Aug 18, 2021 at 7:07 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
> > >
> > > On Tue, Aug 17, 2021 at 1:58 AM Marlon Richert <marlon.richert@gmail.com> wrote:
> > > >
> > > > <Without the patch, when changing selection, highlight continues until
> > > > end of line.>
> > > > <With the patch, it stops at the end of the match, just like the default.>
> > >
> > > And the zcoff() is never needed in the compprintfmt() branch?
> >
> > Hm, good point. How about this patch instead?
>
> Whoops! It looks like I sent the same patch again. Here is now the one
> I actually meant to send. Apologies for the confusion.


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

end of thread, other threads:[~2021-08-20 23:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-17  8:57 [PATCH] complist: Turn off colors before clearing to end of line Marlon Richert
2021-08-18  4:07 ` Bart Schaefer
2021-08-19 19:28   ` Marlon Richert
2021-08-20  6:39     ` Marlon Richert
2021-08-20 23:42       ` 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).