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

Re: [PATCH] complist: Turn off colors before clearing to end of line



On Thu, Aug 19, 2021 at 10:28 PM Marlon Richert
<marlon.richert@xxxxxxxxx> wrote:
>
> On Wed, Aug 18, 2021 at 7:07 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > On Tue, Aug 17, 2021 at 1:58 AM Marlon Richert <marlon.richert@xxxxxxxxx> 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.
From ded9c40e54a3efd458cd78d3b0796bac8206f9af Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlonrichert@xxxxxxxxxxxxxxxxxxxxxxxx>
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



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