Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curses: getmaxyx() breaks when the window shrinks #40504

Closed
doko42 opened this issue Jul 4, 2004 · 6 comments
Closed

curses: getmaxyx() breaks when the window shrinks #40504

doko42 opened this issue Jul 4, 2004 · 6 comments
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@doko42
Copy link
Member

doko42 commented Jul 4, 2004

BPO 984870
Nosy @akuchling, @doko42, @devdanzin, @4kir4

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2014-04-15.15:47:58.810>
created_at = <Date 2004-07-04.11:33:05.000>
labels = ['extension-modules', 'type-bug', 'invalid']
title = 'curses: getmaxyx() breaks when the window shrinks'
updated_at = <Date 2014-04-15.15:47:58.808>
user = 'https://github.com/doko42'

bugs.python.org fields:

activity = <Date 2014-04-15.15:47:58.808>
actor = 'akuchling'
assignee = 'none'
closed = True
closed_date = <Date 2014-04-15.15:47:58.810>
closer = 'akuchling'
components = ['Extension Modules']
creation = <Date 2004-07-04.11:33:05.000>
creator = 'doko'
dependencies = []
files = []
hgrepos = []
issue_num = 984870
keywords = []
message_count = 6.0
messages = ['21400', '21401', '82043', '133937', '216205', '216319']
nosy_count = 5.0
nosy_names = ['akuchling', 'doko', 'chrish42', 'ajaksu2', 'akira']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue984870'
versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

@doko42
Copy link
Member Author

doko42 commented Jul 4, 2004

[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)

@doko42 doko42 added extension-modules C modules in the Modules dir labels Jul 4, 2004
@akuchling
Copy link
Member

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.

@devdanzin
Copy link
Mannequin

devdanzin mannequin commented Feb 14, 2009

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

@devdanzin devdanzin mannequin added type-bug An unexpected behavior, bug, or error labels Feb 14, 2009
@4kir4
Copy link
Mannequin

4kir4 mannequin commented Apr 17, 2011

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

@chrish42
Copy link
Mannequin

chrish42 mannequin commented Apr 14, 2014

I get the same traceback. The traceback happens only when the window is shrunk below the size specified in derwin(). It's easy to see this by changing the first and second arguments to the derwin call to something like 2, 2, and then you can resize the window to a much smaller size without getting this exception. (My curses.version is 2.2 also. Running on OSX Mavericks.)

The getmaxyx() function reports the correct size when the window is shrunk. Also note that the upstream bug has been closed, with the comment "Not seen in python 2.7".

So I think we can close this. Maybe we want to document the behavior of derwin() and related functions of raising _curses.error when the dimensions of the terminal are smaller than that of the window, though? (Or maybe raise a better exception?) That should probably be another bug report, though.

@akuchling
Copy link
Member

I agree with Chris's logic; the incorrect size seems to be a curses/ncurses bug that has gotten fixed somewhere along the line.

You also aren't able to shrink the terminal to be smaller than the size of a derived window created with derwin(), but you seem to get an exception when you try rather than a crash. This seems reasonable to me. I don't think we need to document this behaviour, because that edge case would really belong in the ncurses documentation (and they might change it from version to version).

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants