Why is there no platform independent way of clearing a terminal?

Daniel Fetchinson fetchinson at googlemail.com
Wed Jul 28 07:25:51 EDT 2010


>> > After getting the technicalities out of the way, maybe I should have
>> > asked:
>>
>> > Is it only me or others would find a platform independent python API
>> > to clear the terminal useful?

> I don't know much, but just in case the following is useful to anyone:
>
> There is a Windows program called 'ansicon', which when installed (run
> with '-i'), will modify all future Windows cmd shells to correctly
> intercept and interpret ANSI escape codes for colors, cursor movement,
> and:
>
>       \e[#J     ED: Erase Display
>
> which I presume is what is under discussion here. I understand there
> are other historical ANSI drivers which were responsible for achieving
> a similar thing under Windows, but this is the method I currently use
> (on XP) and am very happy with.
>
> Also, and probably less usefully, personally I do wish Python provided
> a cross platform mechanism for simple  terminal control like clearing
> and colored text. Since ANSI codes are used everywhere except Windows,
> it would make sense to base such a system on them. So I started a pure
> Python implementation of a crude ANSI driver, on PyPI as 'colorama'.
> It does nothing on non-windows systems, but on Windows it patches
> sys.stdout with a stream-like object, in order to filter out ANSI
> codes and convert them into Win32 terminal control calls. It currently
> only works with colors and brightness, but I would love to extend it
> to cover other ANSI codes such as 'clear screen'. It is doubtless
> riddled with errors and misunderstandings, and I would love any
> feedback helping me do a better job.

Thanks, I didn't know about 'colorama' before but it surely looks promising!
I'll look into it for future reference, once in a while I like having
pretty output without the hassle of 'curses' or other complicated
stuff.

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown



More information about the Python-list mailing list