From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: "Zsh Hackers' List" <zsh-workers@sunsite.dk>
Subject: Re: PATCH: curses tweaks, maybe
Date: Sat, 20 Oct 2007 13:12:46 +0100 [thread overview]
Message-ID: <20071020131246.a5257ee6.p.w.stephenson@ntlworld.com> (raw)
In-Reply-To: <20071018204016.GA31055@scowler.net>
On Thu, 18 Oct 2007 16:40:16 -0400
Clint Adams <clint@zsh.org> 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@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
next prev parent reply other threads:[~2007-10-20 12:13 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-16 8:40 Peter Stephenson
2007-10-17 3:29 ` Clint Adams
2007-10-17 8:57 ` Peter Stephenson
2007-10-17 9:14 ` Peter Stephenson
2007-10-17 13:01 ` Clint Adams
2007-10-17 14:57 ` Bart Schaefer
2007-10-17 15:05 ` Peter Stephenson
2007-10-17 15:25 ` Clint Adams
2007-10-17 15:39 ` Peter Stephenson
2007-10-17 18:58 ` Clint Adams
2007-10-17 19:19 ` Clint Adams
2007-10-18 20:40 ` Clint Adams
2007-10-20 12:12 ` Peter Stephenson [this message]
2007-10-20 13:37 ` Clint Adams
2007-10-21 19:50 ` Clint Adams
2007-10-21 21:13 ` Clint Adams
2007-10-17 17:09 ` Bart Schaefer
2007-10-17 17:53 ` 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=20071020131246.a5257ee6.p.w.stephenson@ntlworld.com \
--to=p.w.stephenson@ntlworld.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).