classification
Title: Curses terminal resize problems when Python is in interactive mode
Type: behavior Stage: test needed
Components: Extension Modules Versions: Python 2.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, akuchling, pbazant, r.david.murray
Priority: normal Keywords:

Created on 2008-04-23 15:41 by pbazant, last changed 2010-07-05 15:21 by r.david.murray.

Messages (3)
msg65700 - (view) Author: Pavel Bazant (pbazant) Date: 2008-04-23 15:41
When python is in interactive mode, curses does not react to resize 
events properly.

test.py:

import curses

def run():
 stdscr=curses.initscr()
 key=0
 while(key!=ord('q')):
  key=stdscr.getch()
  stdscr.addstr(0,0,str(stdscr.getmaxyx())+' '+str(key))
  stdscr.refresh()
 curses.endwin()

run()

When this is run directly, everything is ok. When it is called via 
execfile() from the interactive prompt, it shows the right screen size 
after the first keypress, but behaves oddly after the resize.

IMHO, the following happens:
For some reason, env. variables LINES and COLUMNS are set but they are 
not reflected in the os.environ structure nor they respond to screen 
size changes. If these variables are set then the ncurses library (see 
man pages) uses their values instead of getting the term size via 
ioctl. 
The ncurses library receives a SIGWINCH and sees that LINES
and COLUMNS are set. However, their values are same as the
screen dimensions before the resize, so it is perplexed why there is
a SIGWINCH if the screen did not change and it just ungetchs an ERR
and ncurses internal structures are not changed appropriately.

From the resizeterm man page:
"If the environment variables LINES or COLUMNS are set, this overrides 
the library's use of the window size obtained from the operating 
system. Thus, even if a SIGWINCH is received, no screen size change may 
be recorded. In that case, no KEY_RESIZE is queued for the next call to 
getch; an ERR will be returned instead."

Executing

import os
os.environ['LINES']="blah"
del os.environ['LINES']
os.environ['COLUMNS']="blah"
del os.environ['COLUMNS']

solves the problem for me.
Perhaps the problem has sth to do with python using readline
in interactive mode???
PB
msg109298 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-07-05 05:21
Could somebody witht a nix box try this out, I'd do it myself if I had such a beast.
msg109325 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-07-05 15:21
Well, I can run it, but I have no idea what it is telling me or how it demonstrates a bug.  Pavel, is this still a problem in 2.6/2.7?
History
Date User Action Args
2010-07-05 15:21:49r.david.murraysetnosy: + r.david.murray, akuchling
messages: + msg109325

components: + Extension Modules, - None
stage: test needed
2010-07-05 05:21:46BreamoreBoysetnosy: + BreamoreBoy
messages: + msg109298
2008-04-23 15:41:39pbazantcreate