我正在运行一个 Python 的多进程系统,计划使用 curses 将终端窗口分成 4 个象限,并在其中一个象限中显示每个进程的输出。
所以最终的输出应该类似于:
--------------------------------
| | |
| PROCESS01 | PROCESS02 |
| | |
---------------------------------
| | |
| PROCESS03 | PROCESS04 |
| | |
---------------------------------
到目前为止,我尝试将窗口分成四个面板,如下所示:
def main():
screen = curses.initscr()
cols_tot = curses.COLS
rows_tot = curses.LINES
cols_mid = int(0.5*cols_tot) ## middle point of the window
rows_mid = int(0.5*rows_tot)
pad11 = curses.newpad(rows_mid, cols_mid)
pad12 = curses.newpad(rows_mid, cols_mid)
pad21 = curses.newpad(rows_mid, cols_mid)
pad22 = curses.newpad(rows_mid, cols_mid)
pad11.addstr(0, 0, "*** PROCESS 01 ***")
pad12.addstr(0, 0, "*** PROCESS 02 ***")
pad21.addstr(0, 0, "*** PROCESS 03 ***")
pad22.addstr(0, 0, "*** PROCESS 04 ***")
pad11.refresh(0,0, 0,0, rows_mid,cols_mid)
pad12.refresh(0,cols_mid, 0,cols_mid, rows_mid,cols_tot-1)
pad21.refresh(rows_mid,0, rows_mid,0, cols_tot-1,rows_mid)
pad22.refresh(rows_mid, cols_mid, rows_mid,cols_mid, rows_tot-1,cols_tot-1)
curses.napms(3000)
curses.endwin()
if __name__ == '__main__':
main()
但我遇到了错误:
File "screen_show.py", line 78, in <module> main()
File "screen_show.py", line 46, in main
pad12.refresh(0,cols_mid, 0,cols_mid, rows_mid,cols_tot-1)
_curses.error: prefresh() returned ERR
prefresh
函数将返回一个错误。请注意,此函数将在物理屏幕范围内对窗口进行刷新。 - Thomas Dickey