ANSI colored output: How to determine how python was called?
Pearu Peterson
pearu at cens.ioc.ee
Tue May 21 15:10:04 EDT 2002
On 21 May 2002, David M. Cooke wrote:
> I think what you want is something like:
>
> def term_has_colours():
> if not sys.stdout.isatty():
> return 0
> curses.start_color()
> return curses.has_colors()
>
> curses.wrapper does more than you need. I use something like the above
> in my $PYTHONSTARTUP file to give me a coloured prompt.
The problem with the above is that it also needs
curses.initscr()
that in my python prompt messed up the terminal completely so that I have
to blindly exit python and reset the terminal. And
curses.endwin()
did not fixed the mess up either.
That's the reason why I ended up with using curses.wrapper that returns
with properly restoring the current terminal.
Thanks,
Pearu
More information about the Python-list
mailing list