在可以處理調整大小的終端窗口底部打印一行的正確方法是什麼?Python詛咒終端調整大小問題
import curses
from curses import wrapper
def main(stdscr):
inp = 0
y,x = stdscr.getmaxyx()
stdscr.clear()
stdscr.nodelay(1)
while inp != 48 and inp != 27:
stdscr.addnstr(y-1,0, 'I AM KILL TERMINAL WHEN RESIZE AAAAAAAH', x)
inp = stdscr.getch()
wrapper(main)
一旦我調整終端到少的列,則字符串的長度它試圖換到下一行和錯誤的。我在關於禁用包裝的文檔中看不到任何東西。
我試着在addstr函數之前更新我的最大y值。
while inp != 48 and inp != 27:
if (y,x) != stdscr.getmaxyx():
y,x = stdscr.getmaxyx()
stdscr.addnstr(y-1,0, 'I AM KILL TERMINAL WHEN RESIZE AAAAAAAH', x)
inp = stdscr.getch()
我也試着捕捉SIGWINCH
while inp != 48 and inp != 27:
def resize_handler(signum, frame):
stdscr.erase()
stdscr.refresh()
termsize = shutil.get_terminal_size()
curses.resizeterm(termsize[1],termsize[0])
y,x = stdscr.getmaxyx()
signal.signal(signal.SIGWINCH, resize_handler)
stdscr.addnstr(y-1,0, 'I AM KILL TERMINAL WHEN RESIZE AAAAAAAH', x)
inp = stdscr.getch()
但是這些都似乎捕捉到終端更新夠早。
請參考以下鏈接https://開頭的郵件.python.org/pipermail/python-list/2007-February/426098.html – Bijoy