简体   繁体   English

用Python修复窗口而不清除终端

[英]Curses window in Python without clearing the terminal

Is there a way to initialize curses in Python without clearing the existing text in the terminal? 有没有办法在Python中初始化curses而不清除终端中的现有文本? 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 will draw itself over the existing text. 我的想法是,当我执行我的应用程序时,它将“推”现有文本并在屏幕底部执行,或者将自己绘制在现有文本上。 I think curses' newterm function can do that, but it isn't implemented in Python. 我认为curses的newterm函数可以做到这一点,但它没有在Python中实现。 Are there any other ways? 还有其他方法吗?

For simple applications, eg when you just want to use colour, you can try the curses.setupterm function. 对于简单的应用程序,例如,当您只想使用颜色时,可以尝试使用curses.setupterm函数。 The following example uses curses to print red and green text at the bottom of the screen: 以下示例使用curses在屏幕底部打印红色和绿色文本:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM