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

Martin Gregorie martin at address-in-sig.invalid
Wed Jul 28 16:28:23 EDT 2010


On Wed, 28 Jul 2010 09:01:38 -0700, Jonathan Hartley wrote:

> Also, is it crazy to imagine that if colorama was pushed through to
> completion (ie. to support a majority of the relevant ANSI codes) then
> Python's stdlib curses module, unmodified, would suddenly just work on
> Windows? (after a call to 'colorama.init()')
>
Curses was originally built on top of termcap, a much simpler and more 
primitive library. Its abilities are:
- read the termcap database to find and load the capability list
  of the terminal identified as the TERM environment variable.
- write a named capability to the screen. If the capability isn't
  defined for the current terminal its silently ignored.
- fill in x, y and write the cursor movement string
- thats about it.

Its easy enough to find termcap databases. They're just text files 
containing a block of attribute values for each terminal, normally 
including ANSI terminals, Linux consoles, X-terms etc. They are also 
fairly easy to parse, even in vanilla C, so parsing one on Python should 
be a breeze. Termcap format specs and lists of standard attribute names 
are easy enough to find too.

IOW, if you extend colorama to read its codes from a termcap database 
you'll have a basic but easily portable character console handler that 
can at least clear the screen, move the cursor and, if the screen has the 
capability, change the colour of characters or make them bold/dim/blink 
etc.
 
To give you an idea of how complex this is, I've re-implemented termcap 
in Java for my own purposes. It amounts to 1100 lines of fairly well 
spaced and commented Java or about 340 statements, which were estimated 
by counting lines containing semicolons.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |



More information about the Python-list mailing list