By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 1,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

'normal' shell with curses

P: n/a
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
Mar 4 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hello Michael,
I'm trying to print out text in color. As far as I know, curses is the
only way to do that (or not?).
On unix, every XTerm compatible terminal will be able to display color
using escape sequence.
(Like the one you see in the output of 'grep --color')

See the shameless plug in http://pythonwise.blogspot.com/2008/03/ansiprint.html

HTH,
--
Miki <mi*********@gmail.com>
http://pythonwise.blogspot.com
Mar 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.