0

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?

U_0047
  • 1
  • 2
  • It's a compile-time option in libcurses whether you get KEY_RESIZE or not. You can handle it yourself: https://stackoverflow.com/questions/5161552/python-curses-handling-window-terminal-resize – Tim Roberts Oct 17 '22 at 02:51
  • None of the answers in the suggested duplicate actually answer this question. 54520435 is closer... – Thomas Dickey Dec 03 '22 at 01:19

0 Answers0