summary refs log tree commit diff
path: root/Src/Zle
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-04-04 16:32:15 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-04-04 16:32:15 +0000
commit7683ec28aaf395fe1ebc4e619f462fc58f9e02ac (patch)
treed647d4f58497cf4ba091923ea29113c3769eb46d /Src/Zle
parent7eb4302868927de5e0392e22c98c24f64b0055e9 (diff)
downloadzsh-7683ec28aaf395fe1ebc4e619f462fc58f9e02ac.tar.gz
zsh-7683ec28aaf395fe1ebc4e619f462fc58f9e02ac.tar.xz
zsh-7683ec28aaf395fe1ebc4e619f462fc58f9e02ac.zip
24792: try to be safer about turning off attributes when refreshing
Diffstat (limited to 'Src/Zle')
-rw-r--r--Src/Zle/zle_refresh.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index cabefe7e7..b1a5bc83d 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -506,20 +506,34 @@ unset_region_highlight(Param pm, int exp)
 void
 zwcputc(const REFRESH_ELEMENT *c, REFRESH_CHAR *curatrp)
 {
+    /*
+     * Safety: turn attributes off if last heard of turned on.
+     * This differs from *curatrp, which is an optimisation for
+     * writing lots of stuff at once.
+     */
+    static int lastatr;
 #ifdef MULTIBYTE_SUPPORT
     mbstate_t mbstate;
     int i;
     VARARR(char, mbtmp, MB_CUR_MAX + 1);
 #endif
 
+    if (lastatr & ~c->atr) {
+	/* Stuff on we don't want, turn it off */
+	settextattributes((lastatr & ~c->atr) << TXT_ATTR_OFF_ON_SHIFT);
+	lastatr = 0;
+    }
+
     /*
      * Don't output "on" attributes in a string of characters with
      * the same attributes.
      */
     if ((c->atr & TXT_ATTR_ON_MASK) &&
 	(!curatrp ||
-	 ((*curatrp & TXT_ATTR_ON_MASK) != (c->atr & TXT_ATTR_ON_MASK))))
-	settextattributes(c->atr & TXT_ATTR_ON_MASK);
+	 ((*curatrp & TXT_ATTR_ON_MASK) != (c->atr & TXT_ATTR_ON_MASK)))) {
+	lastatr = c->atr & TXT_ATTR_ON_MASK;
+	settextattributes(lastatr);
+    }
 
 #ifdef MULTIBYTE_SUPPORT
     if (c->chr != WEOF) {
@@ -531,8 +545,10 @@ zwcputc(const REFRESH_ELEMENT *c, REFRESH_CHAR *curatrp)
     fputc(c->chr, shout);
 #endif
 
-    if (c->atr & TXT_ATTR_OFF_MASK)
+    if (c->atr & TXT_ATTR_OFF_MASK) {
 	settextattributes(c->atr & TXT_ATTR_OFF_MASK);
+	lastatr &= ~((c->atr & TXT_ATTR_OFF_MASK) >> TXT_ATTR_OFF_ON_SHIFT);
+    }
     if (curatrp) {
 	/*
 	 * Remember the current attributes:  those that are turned