zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: "Zsh hackers list" <zsh-workers@sunsite.dk>
Subject: Re: PATCH: command line highlighting
Date: Fri, 4 Apr 2008 17:28:25 +0100	[thread overview]
Message-ID: <20080404172825.51240903@news01> (raw)
In-Reply-To: <237967ef0804040213p78672a0i795c80bff249b9a9@mail.gmail.com>

On Fri, 4 Apr 2008 11:13:51 +0200
"Mikael Magnusson" <mikachu@gmail.com> wrote:
> The region hilighting acts a bit odd for me, if I type 'hello' press
> ctrl-space and go left, everything appears fine until the cursor
> reaches the "e", at this point the "h" is also hilighted. Tried in
> urxvt and xterm, with zsh -f, with the same result.

This seems to fix it.  The code is written to try to be safe about the
state without being too agressive about writing attributes unnecessarily
and without excessive code.  I don't claim to have balanced the three
things well.

Index: Src/Zle/zle_refresh.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_refresh.c,v
retrieving revision 1.55
diff -u -r1.55 zle_refresh.c
--- Src/Zle/zle_refresh.c	3 Apr 2008 15:33:39 -0000	1.55
+++ Src/Zle/zle_refresh.c	4 Apr 2008 16:22:53 -0000
@@ -506,20 +506,34 @@
 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 @@
     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



-- 
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-04-04 16:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-02 19:39 Peter Stephenson
2008-04-03 10:30 ` Oliver Kiddle
2008-04-03 11:33   ` Peter Stephenson
2008-04-03 14:11     ` Oliver Kiddle
2008-04-03 15:29       ` Peter Stephenson
2008-04-03 15:13     ` Peter Stephenson
2008-04-04  9:13 ` Mikael Magnusson
2008-04-04 16:28   ` Peter Stephenson [this message]
2008-04-06 20:31 ` Bart Schaefer
2008-04-07  9:36   ` 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=20080404172825.51240903@news01 \
    --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).