'normal' shell with curses

Michael Goerz newsgroup898sfie at 8439.e4ward.com
Mon Mar 3 21:57:59 EST 2008


Hi,

I'm trying to print out text in color. As far as I know, curses is the 
only way to do that (or not?). So, what I ultimately want is a curses 
terminal that behaves as closely as possible as a normal terminal, i.e. 
it breaks lines and scrolls automatically, so that I can implement a 
function myprint(color, text) that does what print() does, only in color.

So, my first tests brought up some problems:

#!/usr/bin/python

from time import sleep
import curses
import sys

stdscr = curses.initscr()
stdscr.addstr("Initialized\n")
stdscr.refresh()
(maxlines, maxcolumns) = stdscr.getmaxyx()
try:
     for counter in xrange(24):
         stdscr.addstr("Hello world %s\n" % counter)
         stdscr.refresh()
         if counter >= maxlines:
             stdscr.scroll()
             stdscr.refresh()
except Exception, data:
     sys.stderr.write("Exception: \n");
     sys.stderr.write(str(data));
finally:
     sleep(5)
     curses.endwin()

Instead of scrolling, the program throws an exception. Any hints?

Also, is there a way leave the curses output on the screen after 
curses.endwin(), instead of returning to the normal terminal without a 
trace of curses.

Thanks,
Michael



More information about the Python-list mailing list