zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: random attribute stuff
Date: Tue, 06 May 2008 10:15:40 +0100	[thread overview]
Message-ID: <200805060915.m469FeJP017551@news01.csr.com> (raw)

This is supposed to replace ad hoc code that fixes up text attributes
after the right prompt to use the usual settextattributes() function.
However, having seen the change, it's more ad hoc than I hoped... still,
that's mostly because it now handles changes in colour which it didn't
before.

I'm not completely convinced of the utility of this chunk of code.  It
seems to be designed so that after a right prompt is output everything
is the same as after the normal prompt.  But both before and after this
patch if I let the right prompt leave, say, underline turned on then
when I play with history lines the main line appears underlined, too.  I
don't think it's ever been a good idea to leave effects turned on after
prompts.

Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.129
diff -u -r1.129 zsh.h
--- Src/zsh.h	2 May 2008 22:48:58 -0000	1.129
+++ Src/zsh.h	6 May 2008 09:06:02 -0000
@@ -1983,6 +1983,8 @@
 #define TXT_ATTR_OFF_ON_SHIFT 6
 #define TXT_ATTR_OFF_FROM_ON(attr)	\
     (((attr) & TXT_ATTR_ON_MASK) << TXT_ATTR_OFF_ON_SHIFT)
+#define TXT_ATTR_ON_FROM_OFF(attr)	\
+    (((attr) & TXT_ATTR_OFF_MASK) >> TXT_ATTR_OFF_ON_SHIFT)
 /*
  * Indicates to zle_refresh.c that the character entry is an
  * index into the list of multiword symbols.
Index: Src/Zle/zle_refresh.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_refresh.c,v
retrieving revision 1.65
diff -u -r1.65 zle_refresh.c
--- Src/Zle/zle_refresh.c	1 May 2008 10:58:25 -0000	1.65
+++ Src/Zle/zle_refresh.c	6 May 2008 09:06:03 -0000
@@ -1869,29 +1869,44 @@
 
     /* output the right-prompt if appropriate */
 	if (put_rpmpt && !iln && !oput_rpmpt) {
+	    int attrchange;
+
 	    moveto(0, winw - 1 - rpromptw);
 	    zputs(rpromptbuf, shout);
 	    vcs = winw - 1;
 	/* reset character attributes to that set by the main prompt */
 	    txtchange = pmpt_attr;
-	    if (txtchangeisset(txtchange, TXTNOBOLDFACE) &&
-		(rpmpt_attr & TXTBOLDFACE))
-		tsetcap(TCALLATTRSOFF, 0);
-	    if (txtchangeisset(txtchange, TXTNOSTANDOUT) &&
-		(rpmpt_attr & TXTSTANDOUT))
-		tsetcap(TCSTANDOUTEND, 0);
-	    if (txtchangeisset(txtchange, TXTNOUNDERLINE) &&
-		(rpmpt_attr & TXTUNDERLINE))
-		tsetcap(TCUNDERLINEEND, 0);
-	    if (txtchangeisset(txtchange, TXTBOLDFACE) &&
-		(rpmpt_attr & TXTNOBOLDFACE))
-		tsetcap(TCBOLDFACEBEG, 0);
-	    if (txtchangeisset(txtchange, TXTSTANDOUT) &&
-		(rpmpt_attr & TXTNOSTANDOUT))
-		tsetcap(TCSTANDOUTBEG, 0);
-	    if (txtchangeisset(txtchange, TXTUNDERLINE) &&
-		(rpmpt_attr & TXTNOUNDERLINE))
-		tsetcap(TCUNDERLINEBEG, 0);
+	    /*
+	     * Keep attributes that have actually changed,
+	     * which are ones off in rpmpt_attr and on in
+	     * pmpt_attr, and vice versa.
+	     */
+	    attrchange = txtchange &
+		(TXT_ATTR_OFF_FROM_ON(rpmpt_attr) |
+		 TXT_ATTR_ON_FROM_OFF(rpmpt_attr));
+	    /*
+	     * Careful in case the colour changed.
+	     */
+	    if (txtchangeisset(txtchange, TXTFGCOLOUR) &&
+		(!txtchangeisset(rpmpt_attr, TXTFGCOLOUR) ||
+		 ((txtchange ^ rpmpt_attr) & TXT_ATTR_FG_COL_MASK)))
+	    {
+		attrchange |=
+		    txtchange & (TXTFGCOLOUR | TXT_ATTR_FG_COL_MASK);
+	    }
+	    if (txtchangeisset(txtchange, TXTBGCOLOUR) &&
+		(!txtchangeisset(rpmpt_attr, TXTBGCOLOUR) ||
+		 ((txtchange ^ rpmpt_attr) & TXT_ATTR_BG_COL_MASK)))
+	    {
+		attrchange |=
+		    txtchange & (TXTBGCOLOUR | TXT_ATTR_BG_COL_MASK);
+	    }
+	    /*
+	     * Now feed these changes into the usual function,
+	     * if necessary.
+	     */
+	    if (attrchange)
+		settextattributes(attrchange);
 	}
     }
 


-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


             reply	other threads:[~2008-05-06  9:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-06  9:15 Peter Stephenson [this message]
2008-05-06 14:34 ` Bart Schaefer
2008-05-06 14:42   ` Peter Stephenson
2008-05-06 14:58     ` Bart Schaefer
2008-05-06 15:10       ` Peter Stephenson
2008-05-06 15:38         ` Bart Schaefer
2008-05-06 15:48           ` Peter Stephenson
2008-05-06 18:16             ` Peter Stephenson
2008-05-07 15:44               ` Oliver Kiddle
2008-05-07 15:49               ` Oliver Kiddle
2008-05-07 15:55                 ` Peter Stephenson

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=200805060915.m469FeJP017551@news01.csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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).