468,509 Members | 1,368 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,509 developers. It's quick & easy.

dynamic or on-the-fly color changing in curses?

I'd like to write a class or module in python that allows me to do
on-the-fly color changing in the curses module.

I'm thinking about something along the lines of this:

addstr(y, x, 'hello', brightyellow, blue)

The module would automatically interpret the above as

curses.init_pair(i, curses.COLOR_YELLOW, curses.COLOR_BLUE)
addstr(y, x, 'hello', curses.color_pair(i) | curses.A_BOLD)

What I thought I could get away with is constantly redefining the
same color_pair, as in the following:

curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
scr.addstr(0, 0, 'Hello, world', curses.color_pair(1))

curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK)
scr.addstr(1, 0, 'Hello, world', curses.color_pair(1))

curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
scr.addstr(2, 0, 'Hello, world', curses.color_pair(1))

But when I do that, all strings show up as green. My assumption
here is that all strings are assigned to color_pair(1), and when
those strings are drawn, they assume the most recent definition of
color_pair(1). In other words, it appears you can't "recycle" color
pair definitions.

So my second thought was to just pre-define every possible
combination, but, at least on Linux, I'm limited to 63 unique
colors, whereas I can create more than 63 color combinations
(foreground, background, and attribute combinations).

Am I strictly limited to using at most curses.COLOR_PAIRS colors on
a per-application basis?

Thanks,
Matt

--
Matt Garman
email at: http://raw-sewage.net/index.php?file=email
Jul 18 '05 #1
0 1509

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Neuruss | last post: by
14 posts views Thread by Spare Change | last post: by
1 post views Thread by Chen Sun via .NET 247 | last post: by
5 posts views Thread by Sakcee | last post: by
10 posts views Thread by Zytan | last post: by
1 post views Thread by Tinku | last post: by
4 posts views Thread by aarklon | last post: by
5 posts views Thread by Andrus | last post: by
2 posts views Thread by sachin30 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.