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

Discussion in 'Python' started by Matt Garman, Nov 2, 2004.

  1. Matt Garman

    Matt Garman Guest

    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
     
    Matt Garman, Nov 2, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Skeleton Man

    curses and color

    Skeleton Man, May 25, 2004, in forum: Perl
    Replies:
    0
    Views:
    621
    Skeleton Man
    May 25, 2004
  2. =?Utf-8?B?VmlkdWxh?=
    Replies:
    0
    Views:
    1,644
    =?Utf-8?B?VmlkdWxh?=
    Apr 27, 2006
  3. Jean-Paul Calderone
    Replies:
    2
    Views:
    439
    Joel Hedlund
    Feb 9, 2006
  4. Kamaljeet Saini
    Replies:
    0
    Views:
    431
    Kamaljeet Saini
    Feb 13, 2009
  5. Brian

    Fly outmenu on the fly

    Brian, Apr 8, 2005, in forum: Javascript
    Replies:
    0
    Views:
    111
    Brian
    Apr 8, 2005
Loading...

Share This Page