Colour of output text

Albert van der Horst albert at spenarnc.xs4all.nl
Sun Aug 2 09:54:04 EDT 2009


In article <mailman.3163.1247670223.8015.python-list at python.org>,
Jean-Michel Pichavant  <jeanmichel at sequans.com> wrote:
>Nobody wrote:
>> On Fri, 10 Jul 2009 09:23:54 +0000, garabik-news-2005-05 wrote:
>>
>>
>>>>> I would like to learn a way of changing the colour of a particular
>>>>> part of the output text. I've tried the following
>>>>>
>>>> On Unix operating systems this would be done through the curses interface:
>>>>
>>>> http://docs.python.org/library/curses.html
>>>>
>>> Or using ANSI colour codes:
>>>
>>> colours = {
>>>             'none'       :    "",
>>>             'default'    :    "\033[0m",
>>>             'bold'       :    "\033[1m",
>>>
>>
>> [snip]
>>
>>
>>>             # non-standard attributes, supported by some terminals
>>>
>>
>> This comment should have appeared immediately after "none" ;)
>>
>> 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, 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.

In general initscr() ought to work. It fails if it has no/a wrong
idea of what your terminal is.

In the same shell as you run run your program type

set | grep -i term

Now some entry should show up, e.g.
TERM=xterm

infocmp $TERM

should fetch information about your terminal, from the same source
as curses does.

Possible problems are:
- your operating system/configurations lies to curses about the terminal
  or your terminal is not specified at all
- curses has not been properly installed and cannot find the database

Groetjes Albert


>
>JM
>
>


--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst




More information about the Python-list mailing list