classification
Title: curses: getmaxyx() breaks when the window shrinks
Type: behavior Stage: test needed
Components: Extension Modules Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, akira, akuchling, doko
Priority: normal Keywords:

Created on 2004-07-04 11:33 by doko, last changed 2011-04-17 19:58 by akira.

Messages (4)
msg21400 - (view) Author: Matthias Klose (doko) (Python committer) Date: 2004-07-04 11:33
[forwarded from http://bugs.debian.org/257472]

When derived windows of stdscr have been created,
shrinking the terminal produces a KEY_RESIZE event, but
getmaxyx() returns the previous terminal size. Only by
increasing the window size does it return the correct
terminal dimensions.

A minimal script to show this effect is included below.

#!/usr/bin/python
import curses, sys

def init_display(stdscr):
    stdscr.clear()
    stdscr.refresh()
    size = stdscr.getmaxyx()
    sys.stderr.write("Now %u x %u\n" % (size[1],size[0]))
    rootwin = stdscr.derwin(20, 50, 0, 0)
    return rootwin

def main(stdscr):
    rootwin = init_display(stdscr)
    while 1:
        input = rootwin.getch()
        if ( input == curses.KEY_RESIZE):
            init_display(stdscr)
        elif input == ord("q"):
            sys.exit()
        rootwin.refresh()

curses.wrapper(main)


msg21401 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-07-07 13:19
Logged In: YES 
user_id=11375

Confirmed.  I suspect this is a problem in ncurses, and will
write a C equivalent of the test program to verify this. 
The ncurses man page for derwin says: "The  subwindow 
functions  (subwin,  derwin, ...) are flaky,   incompletely
implemented, and not well tested," so an ncurses bug seems
likely.

msg82043 - (view) Author: Daniel Diniz (ajaksu2) Date: 2009-02-14 12:58
I get a different behavior, with shrinking reporting correct sizes, but
quiting with a "_curses.error: curses function returned NULL", on trunk,
KDE 3.5's Konsole._curses.error: curses function returned NULL
msg133937 - (view) Author: (akira) Date: 2011-04-17 19:58
The test produces a traceback while shrinking a window (increasing the window size works ok):

Traceback (most recent call last):
  File "screen-resize-bug-curses.py", line 22, in <module>
    curses.wrapper(main)
  File "/.../python2.7/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "screen-resize-bug-curses.py", line 17, in main
    init_display(stdscr)
  File "screen-resize-bug-curses.py", line 9, in init_display
    rootwin = stdscr.derwin(20, 50, 0, 0)
_curses.error: curses function returned NULL

Version info:

$ python2.7 -c'import curses; print curses.version'
2.2
History
Date User Action Args
2011-04-17 19:58:34akirasetnosy: + akira
messages: + msg133937
2010-08-19 15:05:13BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2009-02-14 12:58:57ajaksu2setnosy: + ajaksu2
stage: test needed
type: behavior
messages: + msg82043
versions: + Python 2.6, - Python 2.3
2004-07-04 11:33:05dokocreate