From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11723 invoked from network); 20 Oct 2007 12:13:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 20 Oct 2007 12:13:50 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 97116 invoked from network); 20 Oct 2007 12:13:44 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 20 Oct 2007 12:13:44 -0000 Received: (qmail 23768 invoked by alias); 20 Oct 2007 12:13:42 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24001 Received: (qmail 23750 invoked from network); 20 Oct 2007 12:13:41 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 20 Oct 2007 12:13:41 -0000 Received: (qmail 96788 invoked from network); 20 Oct 2007 12:13:41 -0000 Received: from mtaout01-winn.ispmail.ntl.com (81.103.221.47) by a.mx.sunsite.dk with SMTP; 20 Oct 2007 12:13:35 -0000 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com with ESMTP id <20071020121333.WFBW1783.mtaout01-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com> for ; Sat, 20 Oct 2007 13:13:33 +0100 Received: from pws-pc.ntlworld.com ([81.107.45.67]) by aamtaout02-winn.ispmail.ntl.com with SMTP id <20071020121333.EJSJ17393.aamtaout02-winn.ispmail.ntl.com@pws-pc.ntlworld.com> for ; Sat, 20 Oct 2007 13:13:33 +0100 Date: Sat, 20 Oct 2007 13:12:46 +0100 From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: PATCH: curses tweaks, maybe Message-Id: <20071020131246.a5257ee6.p.w.stephenson@ntlworld.com> In-Reply-To: <20071018204016.GA31055@scowler.net> References: <20071016094040.4a48a750@news01> <20071017032955.GA25480@scowler.net> <20071017095724.44acafe1@news01> <200710170914.l9H9Eihs021321@news01.csr.com> <071017075713.ZM30525@torch.brasslantern.com> <200710171505.l9HF5i6b025009@news01.csr.com> <20071017152506.GA30012@scowler.net> <200710171539.l9HFdKWC025510@news01.csr.com> <20071018204016.GA31055@scowler.net> X-Mailer: Sylpheed 2.3.1 (GTK+ 2.10.14; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 18 Oct 2007 16:40:16 -0400 Clint Adams wrote: > On Wed, Oct 17, 2007 at 04:39:19PM +0100, Peter Stephenson wrote: > > zcurses -C window black/red > > I don't know why this doesn't work; perhaps another man page I'm > misreading. This fixes up some problems with hash table usage. I hope there aren't any leaks, it probably wants some looking over. I've also used shorts where the manual page says it needs them; this shouldn't actually be a problem since presumably the prototypes are OK. We may want a more informative message if we run out of color pairs. Otherwise it seems to be working... I'm just using a trivially modified script. If I get a chance I may look at turning the options into names in a table as suggested by Bart. This will also give us a way of doing better argument length and other checking. I've also got a patch necessary for compilation with curses instead of ncurses, but that's at work so will have to wait till Monday. zmodload zsh/curses zcurses -i zcurses -a tw $(( LINES - 10 )) $(( COLUMNS - 20 )) 5 10 zcurses -b tw zcurses -m tw 1 1 zcurses -c tw B zcurses -c tw l zcurses -c tw a zcurses -c tw h zcurses -r tw zcurses -m tw 2 2 zcurses -s tw String zcurses -m tw 3 3 zcurses -C tw blue/red zcurses -A tw +bold +underline zcurses -s tw BoLD zcurses -r tw sleep 5 zcurses -d tw zcurses -e Index: Src/Modules/curses.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/curses.c,v retrieving revision 1.13 diff -u -r1.13 curses.c --- Src/Modules/curses.c 19 Oct 2007 20:21:29 -0000 1.13 +++ Src/Modules/curses.c 20 Oct 2007 12:05:11 -0000 @@ -54,6 +54,12 @@ int number; }; +struct colorpairnode { + struct hashnode node; + short colorpair; +}; +typedef struct colorpairnode *Colorpairnode; + static WINDOW *win_zero; static struct ttyinfo saved_tty_state; static struct ttyinfo curses_tty_state; @@ -70,7 +76,8 @@ #define ZCURSES_ATTRON 1 #define ZCURSES_ATTROFF 2 -static int zc_errno, zc_color_phase=0, next_cp=0; +static int zc_errno, zc_color_phase=0; +static short next_cp=0; static const char * zcurses_strerror(int err) @@ -172,7 +179,7 @@ return 1; } -static int +static short zcurses_color(char *color) { struct zcurses_namenumberpair *zc; @@ -191,19 +198,21 @@ for(zc=(struct zcurses_namenumberpair *)zcurses_colors;zc->name;zc++) if (!strcmp(color, zc->name)) { - return zc->number; + return (short)zc->number; } - return -1; + return (short)-1; } static int zcurses_colorset(WINDOW *w, char *colorpair) { char *fg, *bg, *cp; - int *c, f, b; + short f, b; + Colorpairnode cpn; - if (zc_color_phase==1 || !(c = (int *) gethashnode(zcurses_colorpairs, colorpair))) { + if (zc_color_phase==1 || + !(cpn = (Colorpairnode) gethashnode(zcurses_colorpairs, colorpair))) { zc_color_phase = 2; cp = ztrdup(colorpair); fg = strtok(cp, "/"); @@ -229,26 +238,23 @@ if (init_pair(next_cp, f, b) == ERR) return 1; - c = (int *)zalloc(sizeof(int *)); + cpn = (Colorpairnode)zalloc(sizeof(struct colorpairnode)); - if(!c) + if (!cpn) return 1; - *c = next_cp; - addhashnode(zcurses_colorpairs, colorpair, (void *)c); - } - - fprintf(stderr, "%d\n", *c); + cpn->colorpair = next_cp; + addhashnode(zcurses_colorpairs, ztrdup(colorpair), (void *)cpn); + } - return (wcolor_set(w, *c, NULL) == ERR); + return (wcolor_set(w, cpn->colorpair, NULL) == ERR); } static void -freecolornode(HashNode hn) +freecolorpairnode(HashNode hn) { - int *i = (int *) hn; - - zfree(i, sizeof(int)); + zsfree(hn->nam); + zfree(hn, sizeof(struct colorpairnode)); } /**/ @@ -275,7 +281,7 @@ zcurses_colorpairs->removenode = removehashnode; zcurses_colorpairs->disablenode = NULL; zcurses_colorpairs->enablenode = NULL; - zcurses_colorpairs->freenode = freecolornode; + zcurses_colorpairs->freenode = freecolorpairnode; zcurses_colorpairs->printnode = NULL; } -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/