From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10233 invoked from network); 4 Apr 2008 16:28:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 4 Apr 2008 16:28:51 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 32050 invoked from network); 4 Apr 2008 16:28:46 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 4 Apr 2008 16:28:46 -0000 Received: (qmail 528 invoked by alias); 4 Apr 2008 16:28:44 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24792 Received: (qmail 515 invoked from network); 4 Apr 2008 16:28:43 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 4 Apr 2008 16:28:43 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [85.115.41.190]) by bifrost.dotsrc.org (Postfix) with ESMTP id 43FD082DC37C for ; Fri, 4 Apr 2008 18:28:36 +0200 (CEST) Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly10g.srv.mailcontrol.com (MailControl) with ESMTP id m34GSQVa032232 for ; Fri, 4 Apr 2008 17:28:30 +0100 Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Fri, 4 Apr 2008 17:28:25 +0100 Date: Fri, 4 Apr 2008 17:28:25 +0100 From: Peter Stephenson To: "Zsh hackers list" Subject: Re: PATCH: command line highlighting Message-ID: <20080404172825.51240903@news01> In-Reply-To: <237967ef0804040213p78672a0i795c80bff249b9a9@mail.gmail.com> References: <8360.1207165155@pws-pc> <237967ef0804040213p78672a0i795c80bff249b9a9@mail.gmail.com> Organization: CSR X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.5; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 04 Apr 2008 16:28:25.0707 (UTC) FILETIME=[E83FFBB0:01C89670] X-Scanned-By: MailControl A-08-00-04 (www.mailcontrol.com) on 10.71.0.120 X-Virus-Scanned: ClamAV 0.91.2/6586/Fri Apr 4 16:26:59 2008 on bifrost X-Virus-Status: Clean On Fri, 4 Apr 2008 11:13:51 +0200 "Mikael Magnusson" 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 Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070