Is there a way to initialize curses in Python without clearing the existing text in the terminal? What I have in mind is, that when I will execute my application, it will either "push" the existing text up and executes at the bottom of the screen, or wi开发者_高级运维ll draw itself over the existing text. I think curses' newterm
function can do that, but it isn't implemented in Python. Are there any other ways?
For simple applications, e.g. when you just want to use colour, you can try the curses.setupterm
function. The following example uses curses to print red and green text at the bottom of the screen:
import curses
curses.setupterm()
black_bg = curses.tparm(curses.tigetstr("setab"), 0)
red = curses.tparm(curses.tigetstr("setaf"), 1)
green = curses.tparm(curses.tigetstr("setaf"), 2)
white = curses.tparm(curses.tigetstr("setaf"), 7)
print black_bg+white+"This is "+red+"red"+white
print "and this is "+green+"green"+white+"."
精彩评论