Curses window in Python without clearing the terminal

Is there a way to initialize curses in Python without clearing existing text in a terminal? I mean, when I run my application, it will either “push” the existing text up, or execute it at the bottom of the screen, or draw over the existing text. I think the curses function newtermcan do this, but it is not implemented in Python. Are there any other ways?

+3
source share
1 answer

For simple applications, for example. when you just want to use color, you can try the function curses.setupterm. 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+"."
+1
source

All Articles