Curses in colour?

Rainy sill at optonline.net
Sun May 27 01:01:42 EDT 2001


On 26 May 2001 15:16:17 -0700, Chris Reay <mrchameleon at hotmail.com> wrote:
> I am developing a text user interface and I want to be able to colour
> widgets, backgrounds and so on. My Linux Red Hat 6.2 system definitely
> displays colours; I can see that from my Vim syntax highlighting, for
> example. However my curses application won't, as this function, which
> returns 0 shows:
> 
> import curses
> 
> def testColor():
>     curses.initscr()
>     curses.start_color()
>     retVal = curses.can_change_color()
>     curses.endwin()
>     return retVal
> 
> My interpreter is Python V2.1 built bog-standard from the Python2.1
> tarball.
> 
> Thanks for any help.
> 
> Chris

I don't know if this works in curses, but I used these codes for color
in console non-curses programs:

def colorize(color, text):
    """Return colorized text"""
    col = '\033[0;3'
    if not color: return text
    elif color == 'red': return col + str(1) + 'm' + text + col + str(7) + 'm'
    elif color == 'green': return col + str(2) + 'm' + text + col + str(7) + 'm'
    elif color == 'yellow': return col + str(3) + 'm' + text + col + str(7)+ 'm'
    elif color == 'blue': return col + str(4) + 'm' + text + col + str(7) + 'm'
    elif color == 'magenta': return col + str(5) + 'm' + text + col + str(7)+'m'
    elif color == 'cyan': return col + str(6) + 'm' + text + col + str(7) + 'm'
    elif color == 'white': return col + str(7) + 'm' + text + col + str(7) + 'm'
    elif color == 'gray': return col + str(8) + 'm' + text + col + str(7) + 'm'


-- 
I'll give you anything, everything if you want things
        - Syd



More information about the Python-list mailing list