Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1467933682; bh=mx0PqJjc4E2S8I7FiAyf9ZfuFI7dIVlNb1SwzJMvyso=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=h5IV06nJ2OgYG3p65QnCzU9fIp5UqPpWjTG6BY3iF2rf+ig2jf5GBLZ11Hg45J+Qvdz7aZKwbvjReZsOfZGCISBLrMqYbqoHGJSRyRpXypTmwdKkCaqg3wr3ctSZDiGrvL/65SpooPQlvbj+MUZO7dJElLkYl/6OQsFYkg0ZeOeLbQcQDT2IcVIz7lRxVrdMpqeEXXsIAJdFP8AZmP7MLP5Zeol0zK8gcy9o7q50ApOmJPayC01eCdlqNUnN/Q1w3dbfQ3hB65dzGWzHes8E7VIyEx55AEcGOAWO03X96yUrPkzQNETEL2RwHiqX4ynnkC9Q9u01Wi+Q0F38f7i3pg==
X-Yahoo-Newman-Id: 572239.64081.bm@smtp115.mail.ir2.yahoo.com
X-Yahoo-Newman-Property: ymail-3
X-YMail-OSG: v6Qb8z4VM1naQyUof03Jb5jLtSpKfF7mjIsnJX5i6Brjg6S
 uTcQWRFVHhhqSKOuoZr_wiYYO4ckD3ux5.Nj0ix348oWflB09oZas5zbgmFd
 DMDZg4O7wBfqbza5m3DIwrCKocovTw1.mHQbPgeeTNtfdij_FpOJwg8YtFzd
 lQ8uoHndu4Ortl76Hlyi_aGporyi6574iqiFB8lGwBLjWC5khZG3G.mfwTRE
 UUmp0xtB3Ctb_OmubQZpBk1p8bA9jxkpGkolpr8_iBIsTspFTWtliSF2wAEG
 KmH8CfKIQJdExyFW7Y5ZkLfJzO4Vk_XX_AN8bAEdX__sJCFLFprBR34zMwsx
 PgY4BzVSkUhYvui5X5sFz4VSMhTKwJu_zUUO0uVypgeIi_diRI9I1zwCNish
 bzZARAr9x1wMHnmc.DWbXJLsobYs4xLXxG9NYhG3T_SHDvmJqeSHFwE14G_a
 3_XkbMQjD2p90KapB5XtWvbk8W1D2H6MZyn1Yj5vt.GqNEoc_fL3F1a5_Djq
 2d9oixMUJMB11rup0Yu0W4LlY3BI7ujRha9u1INuMdSU-
X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI-
In-reply-to: <160707100125.ZM23567@torch.brasslantern.com>
From: Oliver Kiddle <okiddle@yahoo.co.uk>
References: <CACW6SB6sRKdtsbFe_ikp1zqP3YRd9grq-xABMGutu4fRvCqM2A@mail.gmail.com> <49130.1467902941@hydra.kiddle.eu> <160707100125.ZM23567@torch.brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: tab completion color inversion
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <55897.1467933681.1@hydra.kiddle.eu>
Date: Fri, 08 Jul 2016 01:21:21 +0200
Message-ID: <55898.1467933681@hydra.kiddle.eu>
X-Seq: zsh-workers 38809

Bart wrote:
> Reactions:
> 
> (1) Is this related to "End boldface also ends background color" thread
> from back in March?

Somewhat related. You can get the same, completion altering attributes
effect, with PROMPT='%S%U%Bhello%b '
I see that was never addressed. The code clearly originally had handling
to reset attributes. The TSC_DIRTY flag is included for escape sequences
that apparently reset other attributes. That includes standout off,
underline end, bold on and bold off. If standout end is dirty, you
have to wonder about the bold off sequence that lacks a termcap entry
(\e[22m). Any terminal I have access has no such issues.

The following patch addresses this by restoring colours in addition to
other attributes when TSC_DIRTY is set. There's still an issue after
completion where a final space character isn't redrawn in standout.
And completion is still sometimes wiping attributes and returning to
defaults.

> (2) As I said in that thread, I don't really follow the semantics of
> the txtchangep pointer, but AND before OR seems sensible in the macro.

txtchangep and txtattrmask seem to be doing much the same thing -
tracking the current attributes. The need for tracking attributes that
have been turned off such as TXTNOBOLDFACE seems a bit odd - wouldn't
the absence of TXTBOLDFACE do the job?

> (3) Swapping the arguments would touch a lot of code and make it hard
> to compare revisions, so the benefits ought to be carefully weighed.

I've not done that then but I did put the AND before the OR.

Oliver

diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index aca676a..e78f1e5 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -1143,8 +1143,7 @@ zrefresh(void)
 	tsetcap(TCALLATTRSOFF, 0);
 	tsetcap(TCSTANDOUTEND, 0);
 	tsetcap(TCUNDERLINEEND, 0);
-	/* cheat on attribute unset */
-	txtunset(TXTBOLDFACE|TXTSTANDOUT|TXTUNDERLINE);
+	txtattrmask = 0;
 
 	if (trashedzle && !clearflag)
 	    reexpandprompt(); 
diff --git a/Src/prompt.c b/Src/prompt.c
index 831c4f9..bb27453 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -523,8 +523,6 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		break;
 	    case 'b':
 		txtchangeset(txtchangep, TXTNOBOLDFACE, TXTBOLDFACE);
-		txtchangeset(txtchangep, TXTNOSTANDOUT, TXTSTANDOUT);
-		txtchangeset(txtchangep, TXTNOUNDERLINE, TXTUNDERLINE);
 		txtunset(TXTBOLDFACE);
 		tsetcap(TCALLATTRSOFF, TSC_PROMPT|TSC_DIRTY);
 		break;
@@ -542,7 +540,8 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		arg = parsecolorchar(arg, 1);
 		if (arg >= 0 && !(arg & TXTNOFGCOLOUR)) {
 		    txtchangeset(txtchangep, arg & TXT_ATTR_FG_ON_MASK,
-				 TXTNOFGCOLOUR);
+				 TXTNOFGCOLOUR | TXT_ATTR_FG_COL_MASK);
+		    txtunset(TXT_ATTR_FG_COL_MASK);
 		    txtset(arg & TXT_ATTR_FG_ON_MASK);
 		    set_colour_attribute(arg, COL_SEQ_FG, TSC_PROMPT);
 		    break;
@@ -557,7 +556,8 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		arg = parsecolorchar(arg, 0);
 		if (arg >= 0 && !(arg & TXTNOBGCOLOUR)) {
 		    txtchangeset(txtchangep, arg & TXT_ATTR_BG_ON_MASK,
-				 TXTNOBGCOLOUR);
+				 TXTNOBGCOLOUR | TXT_ATTR_BG_COL_MASK);
+		    txtunset(TXT_ATTR_BG_COL_MASK);
 		    txtset(arg & TXT_ATTR_BG_ON_MASK);
 		    set_colour_attribute(arg, COL_SEQ_BG, TSC_PROMPT);
 		    break;
@@ -1041,6 +1041,10 @@ tsetcap(int cap, int flags)
 		tsetcap(TCSTANDOUTBEG, flags);
 	    if (txtisset(TXTUNDERLINE))
 		tsetcap(TCUNDERLINEBEG, flags);
+	    if (txtisset(TXTFGCOLOUR))
+		set_colour_attribute(txtattrmask, COL_SEQ_FG, TSC_PROMPT);
+	    if (txtisset(TXTBGCOLOUR))
+		set_colour_attribute(txtattrmask, COL_SEQ_BG, TSC_PROMPT);
 	}
     }
 }
diff --git a/Src/zsh.h b/Src/zsh.h
index eee31da..36fddd0 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2567,7 +2567,7 @@ struct ttyinfo {
 
 #define txtchangeisset(T,X)	((T) & (X))
 #define txtchangeget(T,A)	(((T) & A ## _MASK) >> A ## _SHIFT)
-#define txtchangeset(T, X, Y)	((void)(T && (*T |= (X), *T &= ~(Y))))
+#define txtchangeset(T, X, Y)	((void)(T && (*T &= ~(Y), *T |= (X))))
 
 /*
  * For outputting sequences to change colour: specify foreground

