I am attempting to create handling for manual terminal resizing in my python program that uses the curses module. After a bit of testing, it seems that when the terminal is manually resized, getch() doesn't return KEY_RESIZE but instead returns -1 (for 'no input'). I tested this with the following code in GNOME Terminal and xterm:
import curses
stdscr = curses.initscr()
stdscr.keypad(1)
curses.curs_set(0)
curses.noecho()
curses.cbreak()
while True:
key = stdscr.getch()
stdscr.addstr(0,0, '{} PRESSED'.format(key))
It also appears that curses' "bookkeeping" data such as LINES and COLS are not updated when the screen is manually resized and getch returns -1, which is proving problematic for making any resize handling function. My questions are:
Why is curses returning -1 instead of KEY_RESIZE?
in the absence of a KEY_RESIZE event, is there any way to update curses' knowledge of the physical terminal's size?