我对诅咒很陌生,所以我在python中尝试了一些不同的东西。在
我已经初始化了窗口并为window对象设置了scrollok。我可以添加字符串,并且滚动可以使addstr()在窗口末尾没有任何错误。在
我想要的是,在程序完成后,能够在终端程序(在本例中是tmux或KDE Konsole)中回滚程序输出。在
在我的代码中,如果跳过endwin()调用,至少可以看到输出,但是终端需要一个reset调用才能恢复正常工作。在
而且,即使程序正在运行,在curses窗口向下滚动之后,我也无法在Konsole中滚动查看初始输出。在
#!/usr/bin/env python2
import curses
import time
win = curses.initscr()
win.scrollok(True)
(h,w)=win.getmaxyx()
h = h + 10
while h > 0:
win.addstr("[h=%d] This is a sample string. After 1 second, it will be lost\n" % h)
h = h - 1
win.refresh()
time.sleep(0.05)
time.sleep(1.0)
curses.endwin()
对于这个任务,我建议您使用pad(http://docs.python.org/2/library/curses.html#curses.newpad):
为了在您使用完curses之后将pad的内容保留在控制台上,我将从pad读回内容,结束curses并将内容写入标准输出。在
下面的代码实现了您所描述的。在
相关问题 更多 >
编程相关推荐