0

I had making a program with curses. I want show colored text without curses.init_pair(). Code like this:

#! /usr/bin/env python

import curses

def allcolors():
    """Set the colors.

    The format is: fg*256+bg
    """
    if curses.COLORS**2 < curses.COLOR_PAIRS:
        raise Exception("Can't init all colors.")
    for i in range(8):
        for j in range(8):
            curses.init_pair(i*8+j, i, j)
            pass
        pass
    pass

try:
    stdscr=curses.initscr()
    curses.noecho()
    curses.cbreak()
    stdscr.keypad(True)
    try:
        curses.start_color()
        allcolors()
        canColor=True
    except:
        canColor=False
        pass

    # ---
    stdscr.addstr('%s' % curses.COLORS, curses.color_pair(curses.COLOR_RED*8+curses.COLOR_MAGENTA))
    stdscr.getch()
    # ---

finally:
    if 'stdscr' in locals():
        stdscr.keypad(False)
        curses.echo()
        curses.nocbreak()
        curses.endwin()

But it failed. Not any things showed.

How can I do that? Or how can I set the color pairs regularly?

phao
  • 1
  • 6

0 Answers0