Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: curses tweaks, maybe
- X-seq: zsh-workers 24001
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: "Zsh Hackers' List" <zsh-workers@xxxxxxxxxx>
- Subject: Re: PATCH: curses tweaks, maybe
- Date: Sat, 20 Oct 2007 13:12:46 +0100
- In-reply-to: <20071018204016.GA31055@xxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20071016094040.4a48a750@news01> <20071017032955.GA25480@xxxxxxxxxxx> <20071017095724.44acafe1@news01> <200710170914.l9H9Eihs021321@xxxxxxxxxxxxxx> <071017075713.ZM30525@xxxxxxxxxxxxxxxxxxxxxx> <200710171505.l9HF5i6b025009@xxxxxxxxxxxxxx> <20071017152506.GA30012@xxxxxxxxxxx> <200710171539.l9HFdKWC025510@xxxxxxxxxxxxxx> <20071018204016.GA31055@xxxxxxxxxxx>
On Thu, 18 Oct 2007 16:40:16 -0400
Clint Adams <clint@xxxxxxx> 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 <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author