Colour of output text
Nobody
nobody at nowhere.com
Wed Jul 15 18:31:38 EDT 2009
On Wed, 15 Jul 2009 17:03:30 +0200, Jean-Michel Pichavant wrote:
>> Hard-coding control/escape sequences is just lame. Use the curses modules
>> to obtain the correct sequences for the terminal.
>>
>>
> As the OP I'm really interested in doing so. I currently have all my
> colors hard-coded.
> Now It may be lame but as soon as I call curses.initscr(), it's just
> messing up with my terminal,
Use curses.setupterm() to locate and parse the terminfo/termcap entry
without entering "curses mode". Most curses functions won't work without
calling initscr(), but the terminfo functions will.
> moreover I didn't figure out how to "print
> 'hello'" using curses color codes.
> Anyone has an example ? I'm pretty sure it may fit in one line.
#!/usr/bin/env python
import curses
curses.setupterm()
setaf = curses.tigetstr('setaf')
if not setaf:
setaf = ''
print (curses.tparm(setaf,1) + "hello, " +
curses.tparm(setaf,2) + "world" +
curses.tparm(setaf,0))
More information about the Python-list
mailing list