开发者

Curses window in Python without clearing the terminal

开发者 https://www.devze.com 2023-02-15 18:15 出处:网络
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

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+"."
0

精彩评论

暂无评论...
验证码 换一张
取 消