zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: random attribute stuff
@ 2008-05-06  9:15 Peter Stephenson
  2008-05-06 14:34 ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Stephenson @ 2008-05-06  9:15 UTC (permalink / raw)
  To: Zsh hackers list

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-05-07 16:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-06  9:15 PATCH: random attribute stuff Peter Stephenson
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

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).