我正在使用来自:http ://www.lfd.uci.edu/~gohlke/pythonlibs/#curses 的包 ,我正在制作一个屏幕对象,如下所示:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import curses
import time
class Screen(object):
def __enter__(self):
self.stdscr = curses.initscr()
curses.cbreak()
curses.noecho()
self.stdscr.keypad(1)
curses.curs_set(0)
Y, X = self.stdscr.getmaxyx()
gap = 1
self.bar = self.stdscr.derwin(3, X, 1, 0)
self.threads = self.stdscr.derwin(Y-4-gap, X/2, 4, 0)
self.messages = self.stdscr.derwin(Y-4-gap, X/2 -1, 4, X/2 + 1)
# self.bar.box()
# self.threads.box()
# self.messages.box()
return self
def __exit__(self, type, value, traceback):
curses.nocbreak()
self.stdscr.keypad(0)
curses.echo()
curses.endwin()
def refresh(self):
self.bar.refresh()
self.threads.refresh()
self.messages.refresh()
if __name__ == '__main__':
with Screen() as S:
S.bar.addstr(0, 0, "Hello")
S.refresh()
time.sleep(2)
S.bar.addstr(0, 0, "\rHi")
time.sleep(2)
但是当我实际执行它时,它只是保持为“Hello”而不是覆盖它并打印“hi”
我试过删除 '\r' 但无济于事。
有任何想法吗?