From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26105 invoked from network); 6 May 2008 21:27:19 -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.6 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; 6 May 2008 21:27:19 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 85758 invoked from network); 6 May 2008 21:27:15 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 May 2008 21:27:15 -0000 Received: (qmail 24510 invoked by alias); 6 May 2008 21:27:12 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24957 Received: (qmail 24494 invoked from network); 6 May 2008 21:27:11 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 6 May 2008 21:27:11 -0000 Received: from mtaout03-winn.ispmail.ntl.com (mtaout03-winn.ispmail.ntl.com [81.103.221.49]) by bifrost.dotsrc.org (Postfix) with ESMTP id 21FFB80ED172 for ; Tue, 6 May 2008 23:27:08 +0200 (CEST) Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com with ESMTP id <20080506213134.OEQJ22559.mtaout03-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com> for ; Tue, 6 May 2008 22:31:34 +0100 Received: from pws-pc.ntlworld.com ([81.107.40.67]) by aamtaout03-winn.ispmail.ntl.com with ESMTP id <20080506213442.LESA26699.aamtaout03-winn.ispmail.ntl.com@pws-pc.ntlworld.com> for ; Tue, 6 May 2008 22:34:42 +0100 Received: from pws-pc (pws-pc [127.0.0.1]) by pws-pc.ntlworld.com (8.14.2/8.14.2) with ESMTP id m46LQA5C017833 for ; Tue, 6 May 2008 22:26:10 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: colour sanity checks X-Mailer: MH-E 8.0.3; nmh 1.2-20070115cvs; GNU Emacs 22.1.1 Date: Tue, 06 May 2008 22:26:10 +0100 Message-ID: <17832.1210109170@pws-pc> X-Virus-Scanned: ClamAV 0.91.2/7041/Tue May 6 20:15:04 2008 on bifrost X-Virus-Status: Clean Some playtesting revealed odd things could happen with colours out of the termcap range; I've performed the sanity checking earlier. In addition, I've made all numeric colours on terminals with appropriate termcap sequences use those for consistency. To generate ANSI colour sequences you need to use the names. Index: Doc/Zsh/zle.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v retrieving revision 1.70 diff -u -r1.70 zle.yo --- Doc/Zsh/zle.yo 6 May 2008 20:56:50 -0000 1.70 +++ Doc/Zsh/zle.yo 6 May 2008 21:24:29 -0000 @@ -2180,18 +2180,16 @@ Not all terminals support this and, of those that do, not all provide facilities to test the support, hence the user should decide based on the -terminal type. Most terminals with colour support accept the numbers 0 to -7, and may generate additional colours if the tt(bold) attributes is also -present. Most terminals also have a standard range of colours for those -numbers (though the interpretation of the colour can vary); these colours -can be set by one of the names tt(black), tt(red), tt(green), tt(yellow), -tt(blue), tt(magenta), tt(cyan) and tt(white). Abbreviations are -allowed; tt(b) or tt(bl) selects black. +terminal type. Most terminals support the colours tt(black), tt(red), +tt(green), tt(yellow), tt(blue), tt(magenta), tt(cyan) and tt(white), +which can be set by name. Abbreviations are allowed; tt(b) or tt(bl) +selects black. Some terminals may generate additional colours if the +tt(bold) attribute is also present. On recent terminals and on systems with an up-to-date terminal database the number of colours supported may be tested by with the command `tt(echotc Co)'; if this succeeds, it indicates a limit on the number of colours which -will be enforced by the line editor. The number of colours is in case +will be enforced by the line editor. The number of colours is in any case limited to 256 (i.e. the range 0 to 255). Colour is also known as color. Index: Src/Zle/zle_refresh.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_refresh.c,v retrieving revision 1.67 diff -u -r1.67 zle_refresh.c --- Src/Zle/zle_refresh.c 6 May 2008 18:19:15 -0000 1.67 +++ Src/Zle/zle_refresh.c 6 May 2008 21:24:29 -0000 @@ -460,10 +460,10 @@ found = 0; if (strpfx("fg=", teststr) || strpfx("bg=", teststr)) { int is_fg = (teststr[0] == 'f'); - int colour, shft, on; + int colour, shft, on, named, tc; teststr += 3; - if (ialpha(*teststr)) + if ((named = ialpha(*teststr))) colour = match_colour(&teststr); else colour = (int)zstrtol(teststr, (char **)&teststr, 10); @@ -478,9 +478,33 @@ if (is_fg) { shft = TXT_ATTR_FG_COL_SHIFT; on = TXTFGCOLOUR; + tc = TCFGCOLOUR; } else { shft = TXT_ATTR_BG_COL_SHIFT; on = TXTBGCOLOUR; + tc = TCBGCOLOUR; + } + /* + * Try termcap for numbered characters if posible. + * Don't for named characters, since our best bet + * of getting the names right is with ANSI sequences. + */ + if (!named && tccan(tc)) { + if (tccolours >= 0 && colour >= tccolours) { + /* + * Out of range of termcap colours. + * Can we assume ANSI colours work? + */ + if (colour > 7) + continue; /* No. */ + } else { + /* + * We can handle termcap colours and the number + * is in range, so use termcap. + */ + *on_var |= is_fg ? TXT_ATTR_FG_TERMCAP : + TXT_ATTR_BG_TERMCAP; + } } *on_var |= on | (colour << shft); } else { @@ -1137,8 +1161,11 @@ /* * If we're not restoring the default, and either have a * colour value that is too large for ANSI, or have been told - * to use the termcap sequence (which at the time of writing - * we never are), try to use the termcap sequence. + * to use the termcap sequence, try to use the termcap sequence. + * + * We have already sanitised the values we allow from the + * highlighting variables, so much of this shouldn't be + * necessary at this point, but we might as well be safe. */ if (!def && (colour > 7 || use_termcap)) { /* -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/