zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@zsh.org
Subject: Re: tab completion color inversion
Date: Fri, 08 Jul 2016 01:21:21 +0200	[thread overview]
Message-ID: <55898.1467933681@hydra.kiddle.eu> (raw)
In-Reply-To: <160707100125.ZM23567@torch.brasslantern.com>

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


  reply	other threads:[~2016-07-07 23:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CACW6SB6sRKdtsbFe_ikp1zqP3YRd9grq-xABMGutu4fRvCqM2A@mail.gmail.com>
     [not found] ` <49130.1467902941@hydra.kiddle.eu>
2016-07-07 17:01   ` Bart Schaefer
2016-07-07 23:21     ` Oliver Kiddle [this message]
2016-07-08 17:47       ` Bart Schaefer
2016-07-08 22:00         ` Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55898.1467933681@hydra.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).