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

Re: tab completion color inversion



On 5 Jul, Tristan McLeay wrote:
> For a while now, my zsh has become configured (without my doing) such that
> if I use tab to autocomplete, the inserted text is inverted in color. This
> is fine; I don't mind it and I can see why someone might like it. But then
> any text that I type after that is also inverted, and when I press Enter to
> run the command, the output of the command is also inverted. This is really
> unpleasant.
>
> Can I fix that, so that either nothing is inverted, or only the
> automatically entered text is inverted.

This really depends on what your prompt contains: does it contain colour
settings, does it use %F/%f or literal escape sequences. Try putting %f
in at the end. You might also put a colour reset sequence in POSTEDIT
though this doesn't support prompt escapes. If that fails set
zle_highlight to your choice of colour:
  zle_highlight=( default:fg=black )
There are other values besides default so perhaps read the
documentation on zle_highlight if doing this.

Also, the following patch may help. This is a bug fix but may not be
related.

For the benefit of -workers, in trying to track this, I noted that
prompt expansion collates final attributes into the pmpt_attr variable.
I'm supposing that whatever is left after PS1 but not RPS1 is what
should be used for zle text in the absence of default in zle_highlight?
But the value of this was clearly not right. To see, try the following
and then try some completion. With a bit of fiddling, you'll get a
yellow background.
  zsh -f
  PROMPT='%K{green}:%K{red} '

red is 1, green 2 and yellow 3. It is ORing the colours.

The patch below resets the saved colour first but I'd actually be
inclined to change the following macro to do the AND before the OR.

#define txtchangeset(T, X, Y)diff((void)(T && (*T |= (X), *T &= ~(Y))))

It might also then be logical to swap the X and Y arguments. Most uses
are just something like:
    txtchangeset(txtchangep, TXTSTANDOUT, TXTNOSTANDOUT);

Oliver

diff --git a/Src/prompt.c b/Src/prompt.c
index 831c4f9..ce3aa17 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -541,6 +541,7 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 	    case 'F':
 		arg = parsecolorchar(arg, 1);
 		if (arg >= 0 && !(arg & TXTNOFGCOLOUR)) {
+		    *txtchangep &= ~TXT_ATTR_FG_COL_MASK;
 		    txtchangeset(txtchangep, arg & TXT_ATTR_FG_ON_MASK,
 				 TXTNOFGCOLOUR);
 		    txtset(arg & TXT_ATTR_FG_ON_MASK);
@@ -556,6 +557,7 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 	    case 'K':
 		arg = parsecolorchar(arg, 0);
 		if (arg >= 0 && !(arg & TXTNOBGCOLOUR)) {
+		    *txtchangep &= ~TXT_ATTR_BG_COL_MASK;
 		    txtchangeset(txtchangep, arg & TXT_ATTR_BG_ON_MASK,
 				 TXTNOBGCOLOUR);
 		    txtset(arg & TXT_ATTR_BG_ON_MASK);



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